Skip to content

Commit f983655

Browse files
committed
fix
1 parent 5a87299 commit f983655

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

rules-tests/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector/Fixture/skip_equal_numeric_string.php.inc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ final class SkipIdenticalNumericStringCompareBool
99
{
1010
public function equal()
1111
{
12-
var_dump(true == '1');
13-
var_dump('1' == true);
12+
// maybe compare to numeric string
13+
$value = rand(0, 1) ? '1' : null;
14+
15+
var_dump(true == $value);
16+
var_dump($value == true);
1417
}
1518
}

rules/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,13 @@ public function refactor(Node $node): ?Node
103103

104104
private function shouldSkipCompareNumericString(Type $leftStaticType, Type $rightStaticType): bool
105105
{
106+
// use ! ->no() as to support both yes and maybe
106107
if ($leftStaticType instanceof BooleanType) {
107-
return $rightStaticType->isNumericString()->yes();
108+
return ! $rightStaticType->isNumericString()->no();
108109
}
109110

110111
if ($rightStaticType instanceof BooleanType) {
111-
return $leftStaticType->isNumericString()->yes();
112+
return ! $leftStaticType->isNumericString()->no();
112113
}
113114

114115
return false;

0 commit comments

Comments
 (0)