-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[TypeInfo] Add PhpDocAwareReflectionTypeResolver
#57618
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
Conversation
PhpDocAwareReflectionTypeResolver
src/Symfony/Component/TypeInfo/TypeResolver/PhpDocAwareReflectionTypeResolver.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/TypeInfo/TypeResolver/PhpDocAwareReflectionTypeResolver.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with minor comments
Isn't this outside the scope of TypeInfo and exactly the scope for the PropertyType component? Or what is the difference between these 2 components if TypeInfo is also going to read type information from different sources outside of PHP's native types? |
TypeInfo is about getting the type of any PHP element including class properties but also methods, functions and their parameters. It does it by reading through the most common sources that are built-in types but also docblocks until we don't need them anymore for types. |
To illustrate more, this change unlocks making |
00d8043
to
10fc1c4
Compare
10fc1c4
to
57a5c8a
Compare
57a5c8a
to
c6698ce
Compare
src/Symfony/Component/TypeInfo/TypeResolver/PhpDocAwareReflectionTypeResolver.php
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks awesome and makes phpDoc handling way easier !
I tried to make a phpDoc example from scratch here: symfony/symfony-docs#20014 (comment) (see "Then we extract the phpDoc we want to parse" part), it is very complex without such wrapper !
Unless I'm mistaken the build failure should disappear once merged in 7.2 and is due to 7.2.x-dev being installed as part of property-info's test suite, while this breaks BC in the experimental TypeInfo. |
Thank you @mtarld. |
Add a
PhpDocAwareReflectionTypeResolver
that resolves type on reflections prioritizing PHP documentation.The same feature already exists in the
PropertyInfo
component and improves DX a lot.Installing
phpstan/phpdoc-parser
automatically enables this feature both using the type-info component standalone and the fullstack framework.