-
Notifications
You must be signed in to change notification settings - Fork 506
Add config to check BenevolentUnion #1930
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
5290873
to
706c831
Compare
This pull request has been marked as ready for review. |
@@ -76,6 +76,7 @@ parameters: | |||
checkNullables: false | |||
checkThisOnly: true | |||
checkUnionTypes: false | |||
checkBenevolentUnionTypes: false |
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.
should it be true on bleedingEdge?
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.
CheckUnionTypes is not true on bleedingEdge, so checkBenevolentUnionTypes which is stricter shouldn't be true too.
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.
checkBenevolentUnionTypes
will never be true by default, that's why it's "benevolent".
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.
But I'm kinda worried about someone using the config
checkUnionTypes: false
checkBenevolentUnionTypes: true
what should be the behavior ?
- checking both ?
- checking none ?
- only checking the benevolent ?
- throwing an error ?
src/Rules/RuleLevelHelper.php
Outdated
|
||
if ( | ||
$this->checkBenevolentUnionTypes | ||
&& $acceptedType instanceof BenevolentUnionType |
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.
This is too naive - will not see nested BenevolentUnionType. Needs similar logic as checkExplicitMixed
and use TypeTraverser
.
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.
I have a test for (\DateTimeImmutable|false) and for array<(\DateTimeImmutable|false)>.
What do you have in mind with "nested BenevolentUnionType", I'll add new tests.
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.
I guess things like (float|int)|string
706c831
to
f92afc7
Compare
I think it's fine as it is. Please also send a documentation update to https://phpstan.org/config-reference (https://github.com/phpstan/phpstan/edit/1.9.x/website/src/config-reference.md). Thank you. |
Sure, I started phpstan/phpstan#8234 |
Closes phpstan/phpstan#8223