Skip to content

Commit e3f0297

Browse files
authored
[CodeQuality] Skip used inside static closure on AssertFuncCallToPHPUnitAssertRector (#564)
* [CodeQuality] Skip used inside static closure on AssertFuncCallToPHPUnitAssertRector * fix * fix * fix
1 parent 3b54ca1 commit e3f0297

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\FuncCall\AssertFuncCallToPHPUnitAssertRector\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
final class AssertBoolInTest extends TestCase
8+
{
9+
public function some($response)
10+
{
11+
static function () use ($response) {
12+
assert((bool) $response);
13+
};
14+
}
15+
}

rules/CodeQuality/Rector/FuncCall/AssertFuncCallToPHPUnitAssertRector.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
1313
use PhpParser\Node\Expr\Cast\Bool_;
1414
use PhpParser\Node\Expr\ClassConstFetch;
15+
use PhpParser\Node\Expr\Closure;
1516
use PhpParser\Node\Expr\FuncCall;
1617
use PhpParser\Node\Expr\Instanceof_;
1718
use PhpParser\Node\Expr\MethodCall;
1819
use PhpParser\Node\Expr\StaticCall;
1920
use PhpParser\Node\Expr\Variable;
2021
use PhpParser\Node\Name\FullyQualified;
22+
use PhpParser\NodeVisitor;
2123
use PHPStan\Reflection\ClassReflection;
2224
use Rector\PhpParser\Node\Value\ValueResolver;
2325
use Rector\PHPStan\ScopeFetcher;
@@ -76,14 +78,23 @@ public function test()
7678
*/
7779
public function getNodeTypes(): array
7880
{
79-
return [FuncCall::class];
81+
return [Closure::class, FuncCall::class];
8082
}
8183

8284
/**
83-
* @param FuncCall $node
85+
* @param Closure|FuncCall $node
86+
* @return StaticCall|MethodCall|null|NodeVisitor::DONT_TRAVERSE_CHILDREN
8487
*/
85-
public function refactor(Node $node): StaticCall|MethodCall|null
88+
public function refactor(Node $node): StaticCall|MethodCall|null|int
8689
{
90+
if ($node instanceof Closure) {
91+
if ($node->static) {
92+
return NodeVisitor::DONT_TRAVERSE_CHILDREN;
93+
}
94+
95+
return null;
96+
}
97+
8798
if ($node->isFirstClassCallable()) {
8899
return null;
89100
}

0 commit comments

Comments
 (0)