Skip to content

Commit e1b08b6

Browse files
committed
[CodeQuality] Skip Generator on AssertCompareOnCountableWithMethodToAssertCountRector
1 parent 36961eb commit e1b08b6

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertCompareOnCountableWithMethodToAssertCountRector\Fixture;
4+
5+
final class SkipGenerator extends \PHPUnit\Framework\TestCase
6+
{
7+
public function test()
8+
{
9+
$executedProcesses = $this->get();
10+
$this->assertSame(10, iterator_count($executedProcesses));
11+
}
12+
13+
private function get(): \Generator
14+
{
15+
for ($i = 0; $i < 10; $i++) {
16+
yield $i;
17+
}
18+
}
19+
}

rules/CodeQuality/Rector/MethodCall/AssertCompareOnCountableWithMethodToAssertCountRector.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ public function refactor(Node $node): MethodCall|StaticCall|null
8484
&& $this->isNames($comparedExpr->name, ['count', 'sizeof', 'iterator_count'])
8585
) {
8686
$countArg = $comparedExpr->getArgs()[0];
87+
88+
if ($this->isObjectType($countArg->value, new ObjectType('Generator'))) {
89+
return null;
90+
}
91+
8792
$assertArgs[1] = new Arg($countArg->value);
8893

8994
$node->args = $assertArgs;

0 commit comments

Comments
 (0)