Skip to content

Commit c9bd336

Browse files
authored
[CodingStyle][Php81] Skip used by caller variable on FunctionLikeToFirstClassCallableRector (#7519)
* [CodingStyle][Php81] Skip used by caller variable on FunctionLikeToFirstClassCallableRector * fix
1 parent 7f05799 commit c9bd336

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector\Fixture;
4+
5+
$fn = function ($foo)
6+
{
7+
return $foo($foo);
8+
};
9+
10+
var_dump($fn('strlen'));
11+
12+
?>

rules/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PhpParser\Node;
88
use PhpParser\Node\Arg;
9+
use PhpParser\Node\Expr;
910
use PhpParser\Node\Expr\ArrowFunction;
1011
use PhpParser\Node\Expr\CallLike;
1112
use PhpParser\Node\Expr\Closure;
@@ -133,6 +134,11 @@ private function extractCallLike(Closure|ArrowFunction $node): FuncCall|MethodCa
133134
return null;
134135
}
135136

137+
// dynamic name? skip
138+
if ($callLike->name instanceof Expr) {
139+
return null;
140+
}
141+
136142
return $callLike;
137143
}
138144

0 commit comments

Comments
 (0)