Skip to content

Commit 674248c

Browse files
authored
[CodeQuality] Skip compare to mixed on AssertEqualsToSameRector (#433)
1 parent e01f748 commit 674248c

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

rules-tests/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector/Fixture/assert_same_constant_array.php.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use PHPUnit\Framework\TestCase;
66

77
final class AssertSameConstantArray extends TestCase
88
{
9-
public function test($result)
9+
public function test(array $result)
1010
{
1111
$expected = [1 => 2];
1212
$this->assertEquals($expected, $result);
@@ -23,7 +23,7 @@ use PHPUnit\Framework\TestCase;
2323

2424
final class AssertSameConstantArray extends TestCase
2525
{
26-
public function test($result)
26+
public function test(array $result)
2727
{
2828
$expected = [1 => 2];
2929
$this->assertSame($expected, $result);

rules-tests/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector/Fixture/class_constant.php.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertEqualsToSameRector\
88

99
final class ClassConstant extends TestCase
1010
{
11-
public function test($result)
11+
public function test(string $result)
1212
{
1313
$this->assertEquals(SimpleConstantList::BOTTOM, $result);
1414
}
@@ -26,7 +26,7 @@ use Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertEqualsToSameRector\
2626

2727
final class ClassConstant extends TestCase
2828
{
29-
public function test($result)
29+
public function test(string $result)
3030
{
3131
$this->assertSame(SimpleConstantList::BOTTOM, $result);
3232
}

rules-tests/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector/Fixture/php80_enum.php.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertEqualsToSameRector\
77

88
final class Php80Enum extends TestCase
99
{
10-
public function test($result)
10+
public function test(string $result)
1111
{
1212
$this->assertEquals(SimpleEnum::LEFT, $result);
1313
}
@@ -24,7 +24,7 @@ use Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertEqualsToSameRector\
2424

2525
final class Php80Enum extends TestCase
2626
{
27-
public function test($result)
27+
public function test(string $result)
2828
{
2929
$this->assertSame(SimpleEnum::LEFT, $result);
3030
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertEqualsToSameRector\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
final class SkipCompareMixed extends TestCase
8+
{
9+
public function test(mixed $result)
10+
{
11+
$this->assertEquals('test', $result);
12+
}
13+
}

rules/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ public function refactor(Node $node): ?Node
107107
$secondArgType = TypeCombinator::removeNull($this->nodeTypeResolver->getNativeType($args[1]->value));
108108

109109
// loose comparison
110-
if ($firstArgType instanceof IntegerType && ($secondArgType instanceof FloatType || $secondArgType instanceof MixedType)) {
110+
if ($firstArgType instanceof IntegerType && $secondArgType instanceof FloatType) {
111111
return null;
112112
}
113113

114-
if ($firstArgType instanceof FloatType && ($secondArgType instanceof IntegerType || $secondArgType instanceof MixedType)) {
114+
if ($firstArgType instanceof FloatType && $secondArgType instanceof IntegerType) {
115115
return null;
116116
}
117117

@@ -121,6 +121,11 @@ public function refactor(Node $node): ?Node
121121
)) {
122122
return null;
123123
}
124+
125+
// compare to mixed type is can be anything
126+
if ($secondArgType instanceof MixedType) {
127+
return null;
128+
}
124129
}
125130

126131
$hasChanged = $this->identifierManipulator->renameNodeWithMap($node, self::RENAME_METHODS_MAP);

0 commit comments

Comments
 (0)