-
Notifications
You must be signed in to change notification settings - Fork 540
Fix InvalidComparisonOperationRule for UnionType #4168
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
92d6809
to
de7d558
Compare
de7d558
to
4857b6a
Compare
if ($this->isNumberType($scope, $node->left) && $this->isNumberType($scope, $node->right)) { | ||
$isLeftNumberType = $this->isNumberType($scope, $node->left); | ||
$isRightNumberType = $this->isNumberType($scope, $node->right); | ||
if (($isLeftNumberType && $isRightNumberType) || (!$isLeftNumberType && !$isRightNumberType)) { |
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.
What about xor
instead? :D
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 never used it, i'll try.
Offtopic @ondrejmirtes I saw you merged/review multiple of my PRs. I dunno if you plan a release. I just wanted to inform you I dont have access to a computer until Wednesday. So if you want to include one of my pr (with requested changes) feel free to push on it and if any of these PR introduce a regression I wont be able to fix it before Wednesday.
It's maybe not a big issue for you, just wanted to inform you
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.
It's fine, thank you for letting me know. I don't think there will be a major issue, PHPStan is continuously tested on several real-world projects (millions of LoC) so I know about the real issues pretty soon.
If something still comes up that a lot of people have problem with, they can wait on a one-before-last version before they upgrade.
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.
Simplification was easy finally
e14567b
Thank you! |
@VincentLanglet please see issue bot results for related regression tests: |
Yeah, I sometime forget... Do you think it closes phpstan/phpstan#9386, it's unclear to me... |
@VincentLanglet Unfortunately I don't know how to do it in a secure way. |
Looks like it does close phpstan/phpstan#9386. |
me too. no worries. |
@ondrejmirtes I guess you fear someone could steal the bot token or similar things? maybe the issue-bot could just emit a pull request annotation with a link to the job-summary in case changes are present. this can be done just with a "echo", and without any further api tokens |
I'm not sure about the purpose of the InvalidComparisonOperationRule which seams to forbid comparison between number and object or number and arrays. Technically something like
$int == $array
is supported by php (and 0 == [] for instance).Maybe the message
should be improved, but that's another topic.
Looking at the implementation, both
isPossiblyNullableObjectType
andisPossiblyNullableArrayType
shouldn't use the RuleLevelHelper, because it will removed non-array/non-object on lower level and this is the reason why an error happen on level 6 (and then disappear in level 7).Finally, I notice that currently a comparison between
int
andobject|array
is not reported.This is easy to fix, but since I dunno the whole purpose of this rule, I prefer to ask you first @ondrejmirtes if I should fix it too.
Closes phpstan/phpstan#3364