Skip to content

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.

@nsfisis
Copy link
Author

nsfisis commented Jul 6, 2025

Due to the change in the implementation approach of PR #4079, it appears that this potential issue will no longer cause any actual problems. I will close this PR.

@nsfisis nsfisis closed this Jul 6, 2025
@nsfisis nsfisis deleted the fix/ParserNodeTypeToPHPStanType branch July 6, 2025 09:18
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