finderPlugin = new ArrowClosureVariableFinder; $this->traverser = Traverser::fromPlugin($this->finderPlugin); } /** * Enter arrow function. * * @param ArrowFunction $func Arrow function * * @return Closure */ public function enter(ArrowFunction $func, Context $context): Closure { $nodes = []; foreach ($func->getSubNodeNames() as $node) { $nodes[$node] = $func->{$node}; } $params = []; foreach ($nodes['params'] ?? [] as $param) { $params[$param->var->name] = true; } $this->traverser->traverseAst($func->expr); $nodes['uses'] = \array_keys( \array_intersect_key( \array_diff_key( $this->finderPlugin->getFound(), $params, ), $context->variables->top()->getVariables() ) ); return new Closure($nodes, $func->getAttributes()); } }