Skip to content

Commit 3b011f6

Browse files
committed
LogicalXor is not shortcircuited
1 parent 3a12724 commit 3b011f6

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

Diff for: src/Rules/Comparison/LogicalXorConstantConditionRule.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function processNode(Node $node, Scope $scope): array
6363
}
6464

6565
$rightType = $this->helper->getBooleanType($scope, $node->right);
66-
if ($rightType instanceof ConstantBooleanType && !$scope->isInFirstLevelStatement()) {
66+
if ($rightType instanceof ConstantBooleanType) {
6767
$addTipRight = function (RuleErrorBuilder $ruleErrorBuilder) use ($scope, $node, $tipText): RuleErrorBuilder {
6868
if (!$this->treatPhpDocTypesAsCertain) {
6969
return $ruleErrorBuilder;

Diff for: tests/PHPStan/Rules/Comparison/LogicalXorConstantConditionRuleTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ public function testRule(): void
6565
20,
6666
$tipText,
6767
],
68+
[
69+
'Left side of xor is always true.',
70+
24,
71+
],
72+
[
73+
'Right side of xor is always false.',
74+
24,
75+
],
6876
]);
6977
}
7078

Diff for: tests/PHPStan/Rules/Comparison/data/logical-xor.php

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public function doFoo($a, $b)
2020
if ($a xor $b) {
2121

2222
}
23+
24+
1 xor 0;
2325
}
2426

2527
}

0 commit comments

Comments
 (0)