diff --git a/rules-tests/CodeQuality/Rector/FuncCall/AssertFuncCallToPHPUnitAssertRector/Fixture/skip_in_static_method.php.inc b/rules-tests/CodeQuality/Rector/FuncCall/AssertFuncCallToPHPUnitAssertRector/Fixture/skip_in_static_method.php.inc new file mode 100644 index 00000000..1c650f65 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/FuncCall/AssertFuncCallToPHPUnitAssertRector/Fixture/skip_in_static_method.php.inc @@ -0,0 +1,18 @@ +getMessage(); + } +} + +?> \ No newline at end of file diff --git a/rules/CodeQuality/Rector/FuncCall/AssertFuncCallToPHPUnitAssertRector.php b/rules/CodeQuality/Rector/FuncCall/AssertFuncCallToPHPUnitAssertRector.php index 8538e840..70f720fa 100644 --- a/rules/CodeQuality/Rector/FuncCall/AssertFuncCallToPHPUnitAssertRector.php +++ b/rules/CodeQuality/Rector/FuncCall/AssertFuncCallToPHPUnitAssertRector.php @@ -19,6 +19,7 @@ use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Name\FullyQualified; +use PhpParser\Node\Stmt\ClassMethod; use PhpParser\NodeVisitor; use PHPStan\Reflection\ClassReflection; use Rector\PhpParser\Node\Value\ValueResolver; @@ -78,15 +79,23 @@ public function test() */ public function getNodeTypes(): array { - return [Closure::class, FuncCall::class]; + return [ClassMethod::class, Closure::class, FuncCall::class]; } /** - * @param Closure|FuncCall $node + * @param ClassMethod|Closure|FuncCall $node * @return StaticCall|MethodCall|null|NodeVisitor::DONT_TRAVERSE_CHILDREN */ public function refactor(Node $node): StaticCall|MethodCall|null|int { + if ($node instanceof ClassMethod) { + if ($node->isStatic()) { + return NodeVisitor::DONT_TRAVERSE_CHILDREN; + } + + return null; + } + if ($node instanceof Closure) { if ($node->static) { return NodeVisitor::DONT_TRAVERSE_CHILDREN;