7
7
use PhpParser \Node \Expr \ArrayDimFetch ;
8
8
use PhpParser \Node \Expr \AssignOp \Coalesce as AssignOpCoalesce ;
9
9
use PhpParser \Node \Expr \BinaryOp \Coalesce ;
10
+ use PhpParser \Node \Expr \Closure ;
10
11
use PhpParser \Node \Expr \FuncCall ;
11
12
use PhpParser \Node \Expr \Variable ;
13
+ use PhpParser \Node \FunctionLike ;
12
14
use PhpParser \Node \Identifier ;
13
15
use PhpParser \Node \Param ;
16
+ use PhpParser \Node \Stmt \Class_ ;
14
17
use PhpParser \Node \Stmt \ClassMethod ;
15
18
use PhpParser \Node \Stmt \Function_ ;
16
19
use PhpParser \NodeTraverser ;
@@ -59,10 +62,10 @@ public function resolve(array $item)
59
62
*/
60
63
public function getNodeTypes () : array
61
64
{
62
- return [ClassMethod::class, Function_::class];
65
+ return [ClassMethod::class, Function_::class, Closure::class ];
63
66
}
64
67
/**
65
- * @param ClassMethod|Function_ $node
68
+ * @param ClassMethod|Function_|Closure $node
66
69
*/
67
70
public function refactor (Node $ node ) : ?Node
68
71
{
@@ -86,13 +89,19 @@ public function refactor(Node $node) : ?Node
86
89
return null ;
87
90
}
88
91
/**
89
- * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
92
+ * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike
90
93
*/
91
94
private function isParamAccessedArrayDimFetch (Param $ param , $ functionLike ) : bool
92
95
{
96
+ if ($ functionLike ->stmts === null ) {
97
+ return \false;
98
+ }
93
99
$ paramName = $ this ->getName ($ param );
94
100
$ isParamAccessedArrayDimFetch = \false;
95
- $ this ->traverseNodesWithCallable ($ functionLike , function (Node $ node ) use ($ paramName , &$ isParamAccessedArrayDimFetch ) : ?int {
101
+ $ this ->traverseNodesWithCallable ($ functionLike ->stmts , function (Node $ node ) use ($ paramName , &$ isParamAccessedArrayDimFetch ) : ?int {
102
+ if ($ node instanceof Class_ || $ node instanceof FunctionLike) {
103
+ return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN ;
104
+ }
96
105
if ($ this ->shouldStop ($ node , $ paramName )) {
97
106
// force set to false to avoid too early replaced
98
107
$ isParamAccessedArrayDimFetch = \false;
0 commit comments