Skip to content

Commit 6f9034a

Browse files
authored
[CodeQuality] Skip in static arrow function on PreferPHPUnitThisCallRector (#496)
1 parent 52398e7 commit 6f9034a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
final class SkipInStaticArrowFunction extends TestCase
8+
{
9+
public function testMe()
10+
{
11+
static fn() => self::assertSame(1, 1);
12+
}
13+
}
14+
15+
?>

rules/CodeQuality/Rector/Class_/PreferPHPUnitThisCallRector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Rector\PHPUnit\CodeQuality\Rector\Class_;
66

77
use PhpParser\Node;
8+
use PhpParser\Node\Expr\ArrowFunction;
89
use PhpParser\Node\Expr\Closure;
910
use PhpParser\Node\Expr\MethodCall;
1011
use PhpParser\Node\Expr\StaticCall;
@@ -79,7 +80,7 @@ public function refactor(Node $node): ?Node
7980
$hasChanged = false;
8081

8182
$this->traverseNodesWithCallable($node, function (Node $node) use (&$hasChanged): int|null|MethodCall {
82-
$isInsideStaticFunctionLike = ($node instanceof ClassMethod && $node->isStatic()) || ($node instanceof Closure && $node->static);
83+
$isInsideStaticFunctionLike = ($node instanceof ClassMethod && $node->isStatic()) || (($node instanceof Closure || $node instanceof ArrowFunction) && $node->static);
8384
if ($isInsideStaticFunctionLike) {
8485
return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
8586
}

0 commit comments

Comments
 (0)