> */ public function getNodeTypes() : array { return [TryCatch::class]; } /** * @param TryCatch $node * @return Stmt[]|null|TryCatch|int */ public function refactor(Node $node) { $isEmptyFinallyStmts = !$node->finally instanceof Finally_ || $this->isEmpty($node->finally->stmts); // not empty stmts on finally always executed if (!$isEmptyFinallyStmts) { return null; } if ($this->isEmpty($node->stmts)) { return NodeTraverser::REMOVE_NODE; } if (\count($node->catches) !== 1) { return null; } $onlyCatch = $node->catches[0]; if ($this->isEmpty($onlyCatch->stmts)) { return null; } $onlyCatchStmt = $onlyCatch->stmts[0]; if (!$onlyCatchStmt instanceof Throw_) { return null; } if (!$this->nodeComparator->areNodesEqual($onlyCatch->var, $onlyCatchStmt->expr)) { return null; } return $node->stmts; } /** * @param Stmt[] $stmts */ private function isEmpty(array $stmts) : bool { if ($stmts === []) { return \true; } if (\count($stmts) > 1) { return \false; } return $stmts[0] instanceof Nop; } }