Skip to content

Commit cc4f35c

Browse files
committed
add static call support to AssertSameCountOnCollectionToAssertCountRector
1 parent 8ea2917 commit cc4f35c

2 files changed

Lines changed: 42 additions & 4 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Rector\Doctrine\Tests\TypedCollections\Rector\MethodCall\AssertSameCountOnCollectionToAssertCountRector\Fixture;
4+
5+
use Doctrine\Common\Collections\Collection;
6+
use Webmozart\Assert\Assert;
7+
8+
final class StaticCallAssertCount
9+
{
10+
public Collection $items;
11+
12+
public function someMethod()
13+
{
14+
Assert::assertSame(10, $this->items->count());
15+
}
16+
}
17+
18+
?>
19+
-----
20+
<?php
21+
22+
namespace Rector\Doctrine\Tests\TypedCollections\Rector\MethodCall\AssertSameCountOnCollectionToAssertCountRector\Fixture;
23+
24+
use Doctrine\Common\Collections\Collection;
25+
use Webmozart\Assert\Assert;
26+
27+
final class StaticCallAssertCount
28+
{
29+
public Collection $items;
30+
31+
public function someMethod()
32+
{
33+
Assert::assertCount(10, $this->items);
34+
}
35+
}
36+
37+
?>

rules/TypedCollections/Rector/MethodCall/AssertSameCountOnCollectionToAssertCountRector.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PhpParser\Node;
88
use PhpParser\Node\Arg;
99
use PhpParser\Node\Expr\MethodCall;
10+
use PhpParser\Node\Expr\StaticCall;
1011
use PhpParser\Node\Identifier;
1112
use Rector\Doctrine\TypedCollections\TypeAnalyzer\CollectionTypeDetector;
1213
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
@@ -64,14 +65,14 @@ public function test(): void
6465

6566
public function getNodeTypes(): array
6667
{
67-
return [MethodCall::class];
68+
return [MethodCall::class, StaticCall::class];
6869

6970
}
7071

7172
/**
72-
* @param MethodCall $node
73+
* @param MethodCall|StaticCall $node
7374
*/
74-
public function refactor(Node $node): MethodCall|null
75+
public function refactor(Node $node): MethodCall|StaticCall|null
7576
{
7677
if ($node->isFirstClassCallable()) {
7778
return null;
@@ -81,7 +82,7 @@ public function refactor(Node $node): MethodCall|null
8182
return null;
8283
}
8384

84-
if (! $this->testsNodeAnalyzer->isInTestClass($node)) {
85+
if ($node instanceof MethodCall && ! $this->testsNodeAnalyzer->isInTestClass($node)) {
8586
return null;
8687
}
8788

0 commit comments

Comments
 (0)