-
Notifications
You must be signed in to change notification settings - Fork 15
Support Phpstan array generics #22
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
Support Phpstan array generics #22
Conversation
MichelHartmann
left a comment
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.
Hey @Mirroar, thank you very much for taking your time to provide this pull request.
It looks great, and I will be happy to approve it.
I only found two tiny pieces, I would suggest we get sorted in advance...
custom-standards/Flyeralarm/Sniffs/Docblock/ReturnTypeSniff.php
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| foreach ($matches['nested'] as $index => $match) { | ||
| if (!empty($matches['generic'][$index])) { |
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.
Due to the nature of empty this expression would be false for strings like "0".
Consider checking for null and equality to '' instead.
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.
$matches['generic'][$index] will always either be completely empty because it's an optional expression, or include at least the characters <>, so this should be fine.
I'll still change it if you'd like me to.
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.
Yeah, I would still prefer the explicit check for '' in order to get rid of the infamous empty().
|
Hi @MichelHartmann, I've applied the suggestions we talked about. |
MichelHartmann
left a comment
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.
Hey @Mirroar, thank you very much.
Revert "Merge pull request #22 from Mirroar/phpstan-array-generics" a…
This as support for typehinting in array return types as described in #21. It doesn't add support for array shapes like
array{foo: int, bar: string}, which is also supported by PHPStan. But it's enough to allow both tools to work together on a project.