diff --git a/rules/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector.php b/rules/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector.php index a645bf6b..a5797926 100644 --- a/rules/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector.php +++ b/rules/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector.php @@ -11,6 +11,7 @@ use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Scalar\InterpolatedString; +use PhpParser\Node\Scalar\String_; use PHPStan\Type\BooleanType; use PHPStan\Type\Constant\ConstantArrayType; use PHPStan\Type\Constant\ConstantBooleanType; @@ -142,7 +143,11 @@ private function shouldSkipLooseComparison(array $args): bool } // can happen with magic process - return $secondArgType instanceof NeverType; + if ($secondArgType instanceof NeverType) { + return true; + } + + return $args[0]->value instanceof String_ && is_numeric($args[0]->value->value); } private function shouldSkipConstantArrayType(Expr $expr): bool diff --git a/tests/Issues/AssertEqualsSame/Fixture/assert_equals_numeric_string.php.inc b/tests/Issues/AssertEqualsSame/Fixture/assert_equals_numeric_string.php.inc new file mode 100644 index 00000000..f2a77583 --- /dev/null +++ b/tests/Issues/AssertEqualsSame/Fixture/assert_equals_numeric_string.php.inc @@ -0,0 +1,45 @@ +assertEquals(123, $this->getOrderId()); + } + + private function getOrderId(): string + { + return '0000000000000000000123'; + } +} + +?> +----- +assertEquals('123', $this->getOrderId()); + } + + private function getOrderId(): string + { + return '0000000000000000000123'; + } +} + +?> \ No newline at end of file diff --git a/tests/Issues/AssertEqualsSame/Fixture/skip_assert_equals.php.inc b/tests/Issues/AssertEqualsSame/Fixture/skip_assert_equals.php.inc deleted file mode 100644 index bda8d757..00000000 --- a/tests/Issues/AssertEqualsSame/Fixture/skip_assert_equals.php.inc +++ /dev/null @@ -1,20 +0,0 @@ -assertEquals(123, $this->getOrderId()); - } - - private function getOrderId(): string - { - return '0000000000000000000123'; - } -}