Skip to content

Commit c51a745

Browse files
committed
Updated Rector to commit bee1dae395490dd91a86230e1886b514288dfa62
rectorphp/rector-src@bee1dae [DeadCode] Handle different indirect duplicated on RemoveDuplicatedCaseInSwitchRector (#5236)
1 parent 373eece commit c51a745

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

rules/DeadCode/Rector/Switch_/RemoveDuplicatedCaseInSwitchRector.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,12 @@ private function resolveInsertedByKeys(Switch_ $switch) : array
8989
{
9090
$totalKeys = \count($switch->cases);
9191
$insertByKeys = [];
92+
$appendKey = 0;
9293
foreach ($switch->cases as $key => $case) {
9394
if ($case->stmts === []) {
9495
continue;
9596
}
96-
for ($jumpToKey = $key + 1; $jumpToKey < $totalKeys; ++$jumpToKey) {
97+
for ($jumpToKey = $key + 2; $jumpToKey < $totalKeys; ++$jumpToKey) {
9798
if (!isset($switch->cases[$jumpToKey])) {
9899
continue;
99100
}
@@ -102,9 +103,10 @@ private function resolveInsertedByKeys(Switch_ $switch) : array
102103
}
103104
$nextCase = $switch->cases[$jumpToKey];
104105
unset($switch->cases[$jumpToKey]);
105-
$insertByKeys[$key][] = $nextCase;
106+
$insertByKeys[$key + $appendKey][] = $nextCase;
106107
$this->hasChanged = \true;
107108
}
109+
$appendKey = isset($insertByKeys[$key]) ? \count($insertByKeys[$key]) : 0;
108110
}
109111
return $insertByKeys;
110112
}
@@ -116,9 +118,14 @@ private function insertCaseByKeys(Switch_ $switch, array $insertByKeys) : void
116118
foreach ($insertByKeys as $key => $insertByKey) {
117119
$nextKey = $key + 1;
118120
\array_splice($switch->cases, $nextKey, 0, $insertByKey);
119-
for ($jumpToKey = $key; $jumpToKey < $key + \count($insertByKey); ++$jumpToKey) {
120-
$switch->cases[$jumpToKey]->stmts = [];
121+
}
122+
/** @var Case_|null $previousCase */
123+
$previousCase = null;
124+
foreach ($switch->cases as $case) {
125+
if ($previousCase instanceof Case_ && $this->areSwitchStmtsEqualsAndWithBreak($case, $previousCase)) {
126+
$previousCase->stmts = [];
121127
}
128+
$previousCase = $case;
122129
}
123130
}
124131
private function areSwitchStmtsEqualsAndWithBreak(Case_ $currentCase, Case_ $nextCase) : bool

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = 'c61d8ea90edb04550b6a43f40bd6c6105a997189';
22+
public const PACKAGE_VERSION = 'bee1dae395490dd91a86230e1886b514288dfa62';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2023-11-10 05:53:14';
27+
public const RELEASE_DATE = '2023-11-10 13:57:49';
2828
/**
2929
* @var int
3030
*/

0 commit comments

Comments
 (0)