> */ public function getNodeTypes() : array { return [Do_::class, For_::class, Foreach_::class, While_::class]; } /** * @param Do_|For_|Foreach_|While_ $node */ public function refactor(Node $node) : ?Node { $modified = \false; while ($this->canRemoveLastStatement($node->stmts)) { \array_pop($node->stmts); $modified = \true; } return $modified ? $node : null; } /** * @param Stmt[] $stmts */ private function canRemoveLastStatement(array $stmts) : bool { if ($stmts === []) { return \false; } \end($stmts); $lastKey = \key($stmts); \reset($stmts); $lastStmt = $stmts[$lastKey]; return $this->isRemovable($lastStmt); } private function isRemovable(Stmt $stmt) : bool { if (!$stmt instanceof Continue_) { return \false; } if ($stmt->num instanceof LNumber) { return $stmt->num->value < 2; } return \true; } }