nodeNameResolver = $nodeNameResolver; $this->callMatcher = $callMatcher; } /** * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Expr\Closure|\PhpParser\Node\Stmt\Function_ $functionLike */ public function match(Foreach_ $foreach, $functionLike) : ?VariableAndCallForeach { $call = $this->callMatcher->matchCall($foreach); if (!$call instanceof Node) { return null; } if (!$foreach->valueVar instanceof Variable) { return null; } $variableName = $this->nodeNameResolver->getName($foreach->valueVar); if ($variableName === null) { return null; } return new VariableAndCallForeach($foreach->valueVar, $call, $variableName, $functionLike); } }