Skip to content

Commit 5a87299

Browse files
committed
fix
1 parent 7bf2b9f commit 5a87299

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
namespace Rector\Tests\CodeQuality\Rector\Equal\UseIdenticalOverEqualWithSameTypeRector\Fixture;
44

5-
final class SkipIdenticalNumericString
5+
/**
6+
* @see https://3v4l.org/9XRF6
7+
*/
8+
final class SkipIdenticalNumericStringCompareBool
69
{
710
public function equal()
811
{
9-
var_dump(true == '1'); // true
10-
var_dump(true === '1'); // false
12+
var_dump(true == '1');
13+
var_dump('1' == true);
1114
}
1215
}

rules/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector.php

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

104104
private function shouldSkipCompareNumericString(Type $leftStaticType, Type $rightStaticType): bool
105105
{
106-
if ($leftStaticType->isString()->yes() && $rightStaticType->isNumericString()->yes()) {
107-
return true;
106+
if ($leftStaticType instanceof BooleanType) {
107+
return $rightStaticType->isNumericString()->yes();
108108
}
109109

110-
return $rightStaticType->isString()->yes() && $leftStaticType->isNumericString()->yes();
110+
if ($rightStaticType instanceof BooleanType) {
111+
return $leftStaticType->isNumericString()->yes();
112+
}
113+
114+
return false;
111115
}
112116

113117
private function processIdenticalOrNotIdentical(Equal|NotEqual $node): Identical|NotIdentical

0 commit comments

Comments
 (0)