Skip to content

Commit f403180

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

2 files changed

Lines changed: 41 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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ public function test(): void
6464

6565
public function getNodeTypes(): array
6666
{
67-
return [MethodCall::class];
67+
return [MethodCall::class, Node\Expr\StaticCall::class];
6868

6969
}
7070

7171
/**
72-
* @param MethodCall $node
72+
* @param MethodCall|Node\Expr\StaticCall $node
7373
*/
74-
public function refactor(Node $node): MethodCall|null
74+
public function refactor(Node $node): MethodCall|Node\Expr\StaticCall|null
7575
{
7676
if ($node->isFirstClassCallable()) {
7777
return null;
@@ -81,7 +81,7 @@ public function refactor(Node $node): MethodCall|null
8181
return null;
8282
}
8383

84-
if (! $this->testsNodeAnalyzer->isInTestClass($node)) {
84+
if ($node instanceof MethodCall && ! $this->testsNodeAnalyzer->isInTestClass($node)) {
8585
return null;
8686
}
8787

0 commit comments

Comments
 (0)