Skip to content

wip: Fix ParserNodeTypeToPHPStanType::resolve() so that it can resolve some of static/self/parent #4082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: 2.1.x
Choose a base branch
from

Conversation

nsfisis
Copy link

@nsfisis nsfisis commented Jul 4, 2025

TODO

Related: this issue was found while debugging #4079

@nsfisis
Copy link
Author

nsfisis commented Jul 5, 2025

\PHPStan\Type\ParserNodeTypeToPHPStanType::resolve() returns MixedType when an Identifier of static is passed as $type.

In contrast, \PHPStan\BetterReflection\Reflection\ReflectionClass hardcodes types for BackedEnum::from(), and it returns new Identifier('static'). BackedEnum::tryFrom() is the same except that it returns a nullable type.

https://github.com/ondrejmirtes/BetterReflection/blob/61b25baaca1ea904447f46d975a4ae7c99b722e6/src/Reflection/ReflectionClass.php#L695-L705

I couldn't determine which of the following approaches would be more appropriate:

  • ParserNodeTypeToPHPStanType::resolve() should handle Identifiers of static in the same way it handles Names of static. (this pull request)
  • ReflectionClass should change the return type of BackedEnum::from() from Identifier of static to Name of static.

@ondrejmirtes
Copy link
Member

Hi, where you're encountering this problem? Without a test I don't know what you're trying to fix.

@nsfisis
Copy link
Author

nsfisis commented Jul 5, 2025

Hi, where you're encountering this problem? Without a test I don't know what you're trying to fix.

This pull request addresses a potential issue that we encountered while debugging #4079. However, the original pull request #4079 has changed its approach to fix the problem, so this pull request could become unnecessary.

I will keep this pull request as a draft until the root cause and fix for #4079 become clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants