-
Notifications
You must be signed in to change notification settings - Fork 432
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
Added a rule to check for always true / false result of boolean-xor operations #1502
Conversation
4c2d97e
to
be9149c
Compare
not sure what's going on with the remaining 2 failed actions there, if there's something i need to do let me know |
Oh and I forgot - this new rule has to be registered only in bleedingEdge using the |
…uleHelper. Changed BooleanXorConstantConditionRule to be active only in bleeding edge.
@@ -2292,6 +2293,25 @@ static function (?Type $offsetType, Type $valueType, bool $optional) use (&$arra | |||
|
|||
$this->callNodeCallbackWithExpression($nodeCallback, new BooleanOrNode($expr, $leftResult->getFalseyScope()), $scope, $context); | |||
|
|||
return new ExpressionResult( |
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'm not confident that i've done the right thing here, just winged it based on what the BooleanOrConstantConditionRule is doing and the node structure it relies on.
i would not be surprised if i have overlooked something in this code
return $left xor $right; | ||
} | ||
|
||
function skip(\DateTimeImmutable $date): void |
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 could not figure out a way to write an xor
statement that had neither the left or right being always true or false, while the full statement itself is a boolean constant result.
i tried this but due to the way phpstan models it's types as possibilities and not as branches it doesn't work :(
$val = (bool) rand(0, 1);
$notVal = !$val;
$res = ($val xor $notVal);
if you have any wisdom let me know :)
closes phpstan/phpstan#7539
Adapted the rule from the BooleanOrConstantConditionRule