Skip to content

Commit c0b4dfb

Browse files
authored
[CodeQuality] Skip union type on AssertCountWithZeroToAssertEmptyRector (#459)
1 parent 45b0f6b commit c0b4dfb

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertCountWithZeroToAssertEmptyRector\Fixture;
4+
5+
final class SkipUnionType extends \PHPUnit\Framework\TestCase
6+
{
7+
public function test($something)
8+
{
9+
foreach ([true, false] as $value) {
10+
$count = (int) $value;
11+
$this->assertCount($count, $something);
12+
}
13+
}
14+
}

rules/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PhpParser\Node\Expr\MethodCall;
99
use PhpParser\Node\Expr\StaticCall;
1010
use PhpParser\Node\Name;
11+
use PHPStan\Type\UnionType;
1112
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
1213
use Rector\Rector\AbstractRector;
1314
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@@ -69,6 +70,11 @@ public function refactor(Node $node): MethodCall|StaticCall|null
6970
}
7071

7172
$type = $this->getType($node->getArgs()[0]->value);
73+
74+
if ($type instanceof UnionType) {
75+
return null;
76+
}
77+
7278
$value = ($type->getConstantScalarValues()[0] ?? null);
7379
if ($value === 0) {
7480
$args = $node->getArgs();

0 commit comments

Comments
 (0)