Skip to content

Commit 159ca62

Browse files
authored
[CodeQuality] Skip in static method on AssertFuncCallToPHPUnitAssertRector (#582)
* [CodeQuality] Skip in static method on AssertFuncCallToPHPUnitAssertRector * Fix
1 parent 6b63e9b commit 159ca62

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\FuncCall\AssertFuncCallToPHPUnitAssertRector\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
final class SkipInStaticMethodTest extends TestCase
8+
{
9+
private static function getExceptionMessage(string $fqcn): string
10+
{
11+
$exception = new $fqcn();
12+
assert($exception instanceof \Exception);
13+
14+
return $exception->getMessage();
15+
}
16+
}
17+
18+
?>

rules/CodeQuality/Rector/FuncCall/AssertFuncCallToPHPUnitAssertRector.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use PhpParser\Node\Expr\StaticCall;
2020
use PhpParser\Node\Expr\Variable;
2121
use PhpParser\Node\Name\FullyQualified;
22+
use PhpParser\Node\Stmt\ClassMethod;
2223
use PhpParser\NodeVisitor;
2324
use PHPStan\Reflection\ClassReflection;
2425
use Rector\PhpParser\Node\Value\ValueResolver;
@@ -78,15 +79,23 @@ public function test()
7879
*/
7980
public function getNodeTypes(): array
8081
{
81-
return [Closure::class, FuncCall::class];
82+
return [ClassMethod::class, Closure::class, FuncCall::class];
8283
}
8384

8485
/**
85-
* @param Closure|FuncCall $node
86+
* @param ClassMethod|Closure|FuncCall $node
8687
* @return StaticCall|MethodCall|null|NodeVisitor::DONT_TRAVERSE_CHILDREN
8788
*/
8889
public function refactor(Node $node): StaticCall|MethodCall|null|int
8990
{
91+
if ($node instanceof ClassMethod) {
92+
if ($node->isStatic()) {
93+
return NodeVisitor::DONT_TRAVERSE_CHILDREN;
94+
}
95+
96+
return null;
97+
}
98+
9099
if ($node instanceof Closure) {
91100
if ($node->static) {
92101
return NodeVisitor::DONT_TRAVERSE_CHILDREN;

0 commit comments

Comments
 (0)