Skip to content

Commit 822f34e

Browse files
committed
Merge remote-tracking branch 'origin/1.12.x' into 2.0.x
2 parents 6b66eb0 + 5ff4cab commit 822f34e

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

src/Rules/Comparison/StrictComparisonOfDifferentTypesRule.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ public function processNode(Node $node, Scope $scope): array
6565
if (
6666
(
6767
$leftType->isConstantScalarValue()->yes()
68-
&& $leftType->isString()->yes()
69-
&& $rightType->isConstantScalarValue()->no()
70-
&& $rightType->isString()->yes()
68+
&& !$leftType->isString()->no()
69+
&& !$rightType->isConstantScalarValue()->yes()
70+
&& !$rightType->isString()->no()
7171
&& TrinaryLogic::extremeIdentity($leftType->isLowercaseString(), $rightType->isLowercaseString())->maybe()
7272
) || (
7373
$rightType->isConstantScalarValue()->yes()
74-
&& $rightType->isString()->yes()
75-
&& $leftType->isConstantScalarValue()->no()
76-
&& $leftType->isString()->yes()
74+
&& !$rightType->isString()->no()
75+
&& !$leftType->isConstantScalarValue()->yes()
76+
&& !$leftType->isString()->no()
7777
&& TrinaryLogic::extremeIdentity($leftType->isLowercaseString(), $rightType->isLowercaseString())->maybe()
7878
)
7979
) {

tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@ public function testStrictComparison(): void
266266
996,
267267
'Remove remaining cases below this one and this error will disappear too.',
268268
],
269+
[
270+
'Strict comparison using === between lowercase-string|false and \'AB\' will always evaluate to false.',
271+
1014,
272+
$tipText,
273+
],
269274
],
270275
);
271276
}

tests/PHPStan/Rules/Comparison/data/strict-comparison.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,3 +1002,18 @@ public function doFoo()
10021002
}
10031003

10041004
}
1005+
1006+
class TestLiteralStringVerbosityFix
1007+
{
1008+
1009+
/**
1010+
* @param lowercase-string|false $a
1011+
*/
1012+
public function doFoo($a): void
1013+
{
1014+
if ($a === 'AB') {
1015+
1016+
}
1017+
}
1018+
1019+
}

0 commit comments

Comments
 (0)