From c51a745c509d414f9c044a60ebe44957b719792d Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 10 Nov 2023 06:59:59 +0000 Subject: [PATCH] Updated Rector to commit bee1dae395490dd91a86230e1886b514288dfa62 https://github.com/rectorphp/rector-src/commit/bee1dae395490dd91a86230e1886b514288dfa62 [DeadCode] Handle different indirect duplicated on RemoveDuplicatedCaseInSwitchRector (#5236) --- .../RemoveDuplicatedCaseInSwitchRector.php | 15 +++++++++++---- src/Application/VersionResolver.php | 4 ++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/rules/DeadCode/Rector/Switch_/RemoveDuplicatedCaseInSwitchRector.php b/rules/DeadCode/Rector/Switch_/RemoveDuplicatedCaseInSwitchRector.php index 96858b1bf874..7a8f6dc01343 100644 --- a/rules/DeadCode/Rector/Switch_/RemoveDuplicatedCaseInSwitchRector.php +++ b/rules/DeadCode/Rector/Switch_/RemoveDuplicatedCaseInSwitchRector.php @@ -89,11 +89,12 @@ private function resolveInsertedByKeys(Switch_ $switch) : array { $totalKeys = \count($switch->cases); $insertByKeys = []; + $appendKey = 0; foreach ($switch->cases as $key => $case) { if ($case->stmts === []) { continue; } - for ($jumpToKey = $key + 1; $jumpToKey < $totalKeys; ++$jumpToKey) { + for ($jumpToKey = $key + 2; $jumpToKey < $totalKeys; ++$jumpToKey) { if (!isset($switch->cases[$jumpToKey])) { continue; } @@ -102,9 +103,10 @@ private function resolveInsertedByKeys(Switch_ $switch) : array } $nextCase = $switch->cases[$jumpToKey]; unset($switch->cases[$jumpToKey]); - $insertByKeys[$key][] = $nextCase; + $insertByKeys[$key + $appendKey][] = $nextCase; $this->hasChanged = \true; } + $appendKey = isset($insertByKeys[$key]) ? \count($insertByKeys[$key]) : 0; } return $insertByKeys; } @@ -116,9 +118,14 @@ private function insertCaseByKeys(Switch_ $switch, array $insertByKeys) : void foreach ($insertByKeys as $key => $insertByKey) { $nextKey = $key + 1; \array_splice($switch->cases, $nextKey, 0, $insertByKey); - for ($jumpToKey = $key; $jumpToKey < $key + \count($insertByKey); ++$jumpToKey) { - $switch->cases[$jumpToKey]->stmts = []; + } + /** @var Case_|null $previousCase */ + $previousCase = null; + foreach ($switch->cases as $case) { + if ($previousCase instanceof Case_ && $this->areSwitchStmtsEqualsAndWithBreak($case, $previousCase)) { + $previousCase->stmts = []; } + $previousCase = $case; } } private function areSwitchStmtsEqualsAndWithBreak(Case_ $currentCase, Case_ $nextCase) : bool diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 6d4b88abe83a..e5d0ef5c0658 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 = 'c61d8ea90edb04550b6a43f40bd6c6105a997189'; + public const PACKAGE_VERSION = 'bee1dae395490dd91a86230e1886b514288dfa62'; /** * @api * @var string */ - public const RELEASE_DATE = '2023-11-10 05:53:14'; + public const RELEASE_DATE = '2023-11-10 13:57:49'; /** * @var int */