> */ public function getNodeTypes() : array { return [StmtsAwareInterface::class]; } /** * @param StmtsAwareInterface $node */ public function refactor(Node $node) : ?StmtsAwareInterface { foreach ((array) $node->stmts as $key => $stmt) { if (!$stmt instanceof Return_) { continue; } $previousNode = $node->stmts[$key - 1] ?? null; if (!$previousNode instanceof If_) { return null; } if ($previousNode->elseifs !== []) { return null; } if ($previousNode->else instanceof Else_) { return null; } $countStmt = \count($previousNode->stmts); if ($countStmt === 0) { unset($node->stmts[$key - 1]); return $node; } if ($countStmt > 1) { return null; } $previousFirstStmt = $previousNode->stmts[0]; if (!$previousFirstStmt instanceof Return_) { return null; } if (!$this->nodeComparator->areNodesEqual($previousFirstStmt, $stmt)) { return null; } unset($node->stmts[$key - 1]); return $node; } return null; } }