-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Add generics to ArgumentMetadata::getAttributes #45094
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
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.
Do you need this as a bugfix? We usually merge this kind of change to the feature branch.
src/Symfony/Component/HttpKernel/ControllerMetadata/ArgumentMetadata.php
Outdated
Show resolved
Hide resolved
That reminds me #40783, we should not forget about it 👼 |
Well, do I need it? No, I worked around it already with an instanceof check to calm PHPStan down.. I just assumed this was going to be a simple tweak that could be done as bugfix, but then I noticed the API is kinda bad and thus the types are too broad and yeah.. the usual rabbit hole :) |
Okay, let's target 6.1 then. You never know who's parsing those docblocks these days. 🙈 |
I'm fine rebasing this for 6.1, but the question remains what the better API is.. do others care about fixing the API and deprecating things one way or the other? Or is it just me? :) |
This syntax for conditional types works in psalm, but is not supported in phpstan or in PHPStorm (without the psalm plugin) or other IDEs. So this makes it unacceptable to be used in the Symfony phpdoc. |
phpstan/phpstan#3853 we wait personally, psalm is like a god to me ;);) |
(rebase needed) |
Ok rebased. Added a second method to have cleaner return types. I guess one could add a deprecation warning if you pass |
2a0de9d
to
7475c24
Compare
Thank you @Seldaek. |
This PR was squashed before being merged into the 6.1 branch. Discussion ---------- Make use of the new getAttributesOfType method Refs #45094 | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> <!-- Replace this notice by a short README for your feature/bugfix. This will help reviewers and should be a good start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too.) - Features and deprecations must be submitted against the latest branch. - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - Never break backward compatibility (see https://symfony.com/bc). --> Use the new method from #45094 Commits ------- b1fb345 Make use of the new getAttributesOfType method
This is a bit of an unfortunate situation because the function does too many things. If stronger typing was applied earlier on, it would have been evident that typing this correctly is pretty much impossible, and that would have helped guide the design to use a separate function to retrieve all attributes and some attributes.
e.g. the ideal outcome would be for
getAttributes(Foo::class)
to be typed as such:So that the result is guaranteed to be an array of Foo objects.
The fact that $name is nullable throws all this off though.. So I guess the only good way forward would be to deprecate null, or deprecate passing
$name
and add agetAttributesByClassName(string $class, int $flags = 0)
?I'm not sure if merging this as is is valuable or not, or if you'd rather get the deprecation and new method targetting 6.1?