Skip to content

Commit

Permalink
LogicalXor is not shortcircuited
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Dec 7, 2023
1 parent 3a12724 commit 3b011f6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Rules/Comparison/LogicalXorConstantConditionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function processNode(Node $node, Scope $scope): array
}

$rightType = $this->helper->getBooleanType($scope, $node->right);
if ($rightType instanceof ConstantBooleanType && !$scope->isInFirstLevelStatement()) {
if ($rightType instanceof ConstantBooleanType) {
$addTipRight = function (RuleErrorBuilder $ruleErrorBuilder) use ($scope, $node, $tipText): RuleErrorBuilder {
if (!$this->treatPhpDocTypesAsCertain) {
return $ruleErrorBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ public function testRule(): void
20,
$tipText,
],
[
'Left side of xor is always true.',
24,
],
[
'Right side of xor is always false.',
24,
],
]);
}

Expand Down
2 changes: 2 additions & 0 deletions tests/PHPStan/Rules/Comparison/data/logical-xor.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public function doFoo($a, $b)
if ($a xor $b) {

}

1 xor 0;
}

}

0 comments on commit 3b011f6

Please sign in to comment.