Skip to content

Commit

Permalink
Updated Rector to commit bee1dae395490dd91a86230e1886b514288dfa62
Browse files Browse the repository at this point in the history
rectorphp/rector-src@bee1dae [DeadCode] Handle different indirect duplicated on RemoveDuplicatedCaseInSwitchRector (#5236)
  • Loading branch information
TomasVotruba committed Nov 10, 2023
1 parent 373eece commit c51a745
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit c51a745

Please sign in to comment.