> */ public function getNodeTypes() : array { return [ClassMethod::class, Function_::class, Closure::class]; } /** * @param ClassMethod|Function_|Closure $node */ public function refactor(Node $node) : ?Node { if ($node->stmts === [] || $node->stmts === null) { return null; } \end($node->stmts); $lastStmtKey = \key($node->stmts); $lastStmt = $node->stmts[$lastStmtKey]; if ($lastStmt instanceof If_) { if (!$this->isBareIfWithOnlyStmtEmptyReturn($lastStmt)) { return null; } $lastStmt->stmts = []; return $node; } if (!$lastStmt instanceof Return_) { return null; } if ($lastStmt->expr instanceof Expr) { return null; } unset($node->stmts[$lastStmtKey]); return $node; } private function isBareIfWithOnlyStmtEmptyReturn(If_ $if) : bool { if ($if->else instanceof Else_) { return \false; } if ($if->elseifs !== []) { return \false; } if (\count($if->stmts) !== 1) { return \false; } $onlyStmt = $if->stmts[0]; if (!$onlyStmt instanceof Return_) { return \false; } return !$onlyStmt->expr instanceof Expr; } }