diff --git a/rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/Fixture/skip_union_type.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/Fixture/skip_union_type.php.inc new file mode 100644 index 00000000..f174f98c --- /dev/null +++ b/rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/Fixture/skip_union_type.php.inc @@ -0,0 +1,14 @@ +assertCount($count, $something); + } + } +} diff --git a/rules/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector.php b/rules/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector.php index 16cb96f3..48c822d8 100644 --- a/rules/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector.php +++ b/rules/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector.php @@ -8,6 +8,7 @@ use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Name; +use PHPStan\Type\UnionType; use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -69,6 +70,11 @@ public function refactor(Node $node): MethodCall|StaticCall|null } $type = $this->getType($node->getArgs()[0]->value); + + if ($type instanceof UnionType) { + return null; + } + $value = ($type->getConstantScalarValues()[0] ?? null); if ($value === 0) { $args = $node->getArgs();