From 956294f29423a4b74dd5feefddad9f47720b69bc Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 11 Nov 2025 10:50:06 +0700 Subject: [PATCH 1/2] [CodeQuality] Skip in static method on AssertFuncCallToPHPUnitAssertRector --- .../Fixture/skip_in_static_method.php.inc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 rules-tests/CodeQuality/Rector/FuncCall/AssertFuncCallToPHPUnitAssertRector/Fixture/skip_in_static_method.php.inc 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 From 28fde1a454d3a4c05328ad2c88465f17a33fe668 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 11 Nov 2025 10:52:13 +0700 Subject: [PATCH 2/2] Fix --- .../AssertFuncCallToPHPUnitAssertRector.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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;