simpleCallableNodeTraverser = $simpleCallableNodeTraverser; $this->betterNodeFinder = $betterNodeFinder; $this->nodeComparator = $nodeComparator; } /** * @param Stmt[] $stmts */ public function getUnwrappedLastStmt(array $stmts) : ?Node { \end($stmts); $lastStmtKey = \key($stmts); \reset($stmts); $lastStmt = $stmts[$lastStmtKey]; if ($lastStmt instanceof Expression) { return $lastStmt->expr; } return $lastStmt; } /** * @param Stmt[] $stmts * @return Stmt[] */ public function filterOutExistingStmts(ClassMethod $classMethod, array $stmts) : array { $this->simpleCallableNodeTraverser->traverseNodesWithCallable((array) $classMethod->stmts, function (Node $node) use(&$stmts) { foreach ($stmts as $key => $assign) { if (!$this->nodeComparator->areNodesEqual($node, $assign)) { continue; } unset($stmts[$key]); } return null; }); return $stmts; } public function isVariableUsedInNextStmt(StmtsAwareInterface $stmtsAware, int $jumpToKey, string $variableName) : bool { if ($stmtsAware->stmts === null) { return \false; } $stmts = \array_slice($stmtsAware->stmts, $jumpToKey, null, \true); return (bool) $this->betterNodeFinder->findVariableOfName($stmts, $variableName); } }