Skip to content

Commit 5ff4cab

Browse files
committed
Fix
1 parent 23c53a2 commit 5ff4cab

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

src/Rules/Comparison/StrictComparisonOfDifferentTypesRule.php

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

tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,11 @@ public function testStrictComparison(): void
270270
996,
271271
'Remove remaining cases below this one and this error will disappear too.',
272272
],
273+
[
274+
'Strict comparison using === between lowercase-string|false and \'AB\' will always evaluate to false.',
275+
1014,
276+
$tipText,
277+
],
273278
],
274279
);
275280
}
@@ -423,6 +428,11 @@ public function testStrictComparisonWithoutAlwaysTrue(): void
423428
'Strict comparison using !== between INF and INF will always evaluate to false.',
424429
982,
425430
],
431+
[
432+
'Strict comparison using === between lowercase-string|false and \'AB\' will always evaluate to false.',
433+
1014,
434+
$tipText,
435+
],
426436
],
427437
);
428438
}

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)