diff --git a/rules/DeadCode/Rector/Switch_/RemoveDuplicatedCaseInSwitchRector.php b/rules/DeadCode/Rector/Switch_/RemoveDuplicatedCaseInSwitchRector.php index 13d1e8b46eff..688ae52660a0 100644 --- a/rules/DeadCode/Rector/Switch_/RemoveDuplicatedCaseInSwitchRector.php +++ b/rules/DeadCode/Rector/Switch_/RemoveDuplicatedCaseInSwitchRector.php @@ -90,10 +90,14 @@ private function resolveInsertedByKeys(Switch_ $switch) : array $totalKeys = \count($switch->cases); $insertByKeys = []; $appendKey = 0; + /** @var Case_|null $previousCase */ + $previousCase = null; foreach ($switch->cases as $key => $case) { - if ($case->stmts === []) { - continue; + if ($previousCase instanceof Case_ && $this->areSwitchStmtsEqualsAndWithBreak($case, $previousCase)) { + $previousCase->stmts = []; + $this->hasChanged = \true; } + $previousCase = $case; for ($jumpToKey = $key + 2; $jumpToKey < $totalKeys; ++$jumpToKey) { if (!isset($switch->cases[$jumpToKey])) { continue; @@ -118,20 +122,13 @@ private function insertCaseByKeys(Switch_ $switch, array $insertByKeys) : void foreach ($insertByKeys as $key => $insertByKey) { $nextKey = $key + 1; \array_splice($switch->cases, $nextKey, 0, $insertByKey); - } - /** @var Case_|null $previousCase */ - $previousCase = null; - foreach ($switch->cases as $case) { - if ($previousCase instanceof Case_ && $this->areSwitchStmtsEqualsAndWithBreak($case, $previousCase)) { - $previousCase->stmts = []; - $this->hasChanged = \true; - } - $previousCase = $case; + $switch->cases[$key]->stmts = []; + $this->hasChanged = \true; } } - private function areSwitchStmtsEqualsAndWithBreak(Case_ $currentCase, Case_ $nextCase) : bool + private function areSwitchStmtsEqualsAndWithBreak(Case_ $currentCase, Case_ $nextOrPrevCase) : bool { - if (!$this->nodeComparator->areNodesEqual($currentCase->stmts, $nextCase->stmts)) { + if (!$this->nodeComparator->areNodesEqual($currentCase->stmts, $nextOrPrevCase->stmts)) { return \false; } foreach ($currentCase->stmts as $stmt) { diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 0b32770a24f5..a2e88cf8ab9e 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = 'b0d4b15c3fd96582c6e3ed4d21cf4d30eb8742ce'; + public const PACKAGE_VERSION = 'eac58be00246ea8c89548289f2cc742e8b1b6b1a'; /** * @api * @var string */ - public const RELEASE_DATE = '2023-11-10 08:58:55'; + public const RELEASE_DATE = '2023-11-10 19:34:50'; /** * @var int */