diff --git a/rules/DeadCode/Rector/Switch_/RemoveDuplicatedCaseInSwitchRector.php b/rules/DeadCode/Rector/Switch_/RemoveDuplicatedCaseInSwitchRector.php index ad238a4b246..43af54d2a4b 100644 --- a/rules/DeadCode/Rector/Switch_/RemoveDuplicatedCaseInSwitchRector.php +++ b/rules/DeadCode/Rector/Switch_/RemoveDuplicatedCaseInSwitchRector.php @@ -177,10 +177,16 @@ private function areSwitchStmtsEqualsAndWithBreak(Case_ $currentCase, Case_ $nex return $this->areSwitchStmtsEqualsConsideringComments($currentCase, $nextCase); } - if (! $this->nodeComparator->areNodesEqual($currentCase->stmts, $nextCase->stmts)) { + if (count($currentCase->stmts) !== count($nextCase->stmts)) { return false; } + foreach ($currentCase->stmts as $key => $currentStmt) { + if (! $this->nodeComparator->areNodesEqual($currentStmt, $nextCase->stmts[$key])) { + return false; + } + } + return array_any( $currentCase->stmts, fn (Stmt $stmt): bool => $stmt instanceof Break_ || $stmt instanceof Return_