diff --git a/rules-tests/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector/Fixture/skip_loose_compare_nullable.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector/Fixture/skip_loose_compare_nullable.php.inc new file mode 100644 index 00000000..b9d641de --- /dev/null +++ b/rules-tests/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector/Fixture/skip_loose_compare_nullable.php.inc @@ -0,0 +1,18 @@ +assertEquals(1.0, $this->get()); + } + + private function get(): ?int + { + return 1; + } +} diff --git a/rules/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector.php b/rules/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector.php index a92eca87..3986061f 100644 --- a/rules/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector.php +++ b/rules/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector.php @@ -18,6 +18,7 @@ use PHPStan\Type\MixedType; use PHPStan\Type\StringType; use PHPStan\Type\Type; +use PHPStan\Type\TypeCombinator; use Rector\PHPUnit\NodeAnalyzer\IdentifierManipulator; use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer; use Rector\Rector\AbstractRector; @@ -102,7 +103,7 @@ public function refactor(Node $node): ?Node if ($this->isName($node->name, 'assertEquals')) { $firstArgType = $this->nodeTypeResolver->getNativeType($args[0]->value); - $secondArgType = $this->nodeTypeResolver->getNativeType($args[1]->value); + $secondArgType = TypeCombinator::removeNull($this->nodeTypeResolver->getNativeType($args[1]->value)); // loose comparison if ($firstArgType instanceof IntegerType && ($secondArgType instanceof FloatType || $secondArgType instanceof MixedType)) {