From 8aab7ce1dda0ecc1d17c7b8638769f0acea6bcbe Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 29 May 2025 11:09:58 +0700 Subject: [PATCH] [CodeQuality] Skip in static arrow function on PreferPHPUnitThisCallRector --- .../Fixture/skip_in_static_arrow_function.php.inc | 15 +++++++++++++++ .../Rector/Class_/PreferPHPUnitThisCallRector.php | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 rules-tests/CodeQuality/Rector/Class_/PreferPHPUnitThisCallRector/Fixture/skip_in_static_arrow_function.php.inc diff --git a/rules-tests/CodeQuality/Rector/Class_/PreferPHPUnitThisCallRector/Fixture/skip_in_static_arrow_function.php.inc b/rules-tests/CodeQuality/Rector/Class_/PreferPHPUnitThisCallRector/Fixture/skip_in_static_arrow_function.php.inc new file mode 100644 index 00000000..28d0030d --- /dev/null +++ b/rules-tests/CodeQuality/Rector/Class_/PreferPHPUnitThisCallRector/Fixture/skip_in_static_arrow_function.php.inc @@ -0,0 +1,15 @@ + self::assertSame(1, 1); + } +} + +?> \ No newline at end of file diff --git a/rules/CodeQuality/Rector/Class_/PreferPHPUnitThisCallRector.php b/rules/CodeQuality/Rector/Class_/PreferPHPUnitThisCallRector.php index fab8ae12..51e8e4e8 100644 --- a/rules/CodeQuality/Rector/Class_/PreferPHPUnitThisCallRector.php +++ b/rules/CodeQuality/Rector/Class_/PreferPHPUnitThisCallRector.php @@ -5,6 +5,7 @@ namespace Rector\PHPUnit\CodeQuality\Rector\Class_; use PhpParser\Node; +use PhpParser\Node\Expr\ArrowFunction; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; @@ -79,7 +80,7 @@ public function refactor(Node $node): ?Node $hasChanged = false; $this->traverseNodesWithCallable($node, function (Node $node) use (&$hasChanged): int|null|MethodCall { - $isInsideStaticFunctionLike = ($node instanceof ClassMethod && $node->isStatic()) || ($node instanceof Closure && $node->static); + $isInsideStaticFunctionLike = ($node instanceof ClassMethod && $node->isStatic()) || (($node instanceof Closure || $node instanceof ArrowFunction) && $node->static); if ($isInsideStaticFunctionLike) { return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN; }