mirror of https://github.com/rectorphp/rector.git
Updated Rector to commit c61d8ea90edb04550b6a43f40bd6c6105a997189
c61d8ea90e
[DeadCode] Reduce double loop on RemoveDuplicatedCaseInSwitchRector (#5235)
This commit is contained in:
parent
e51766f9ec
commit
373eece1e0
|
@ -77,7 +77,6 @@ CODE_SAMPLE
|
|||
$this->hasChanged = \false;
|
||||
$insertByKeys = $this->resolveInsertedByKeys($node);
|
||||
$this->insertCaseByKeys($node, $insertByKeys);
|
||||
$this->cleanUpEqualCaseStmts($node);
|
||||
if (!$this->hasChanged) {
|
||||
return null;
|
||||
}
|
||||
|
@ -94,7 +93,6 @@ CODE_SAMPLE
|
|||
if ($case->stmts === []) {
|
||||
continue;
|
||||
}
|
||||
$nextKey = $key + 1;
|
||||
for ($jumpToKey = $key + 1; $jumpToKey < $totalKeys; ++$jumpToKey) {
|
||||
if (!isset($switch->cases[$jumpToKey])) {
|
||||
continue;
|
||||
|
@ -102,9 +100,6 @@ CODE_SAMPLE
|
|||
if (!$this->areSwitchStmtsEqualsAndWithBreak($case, $switch->cases[$jumpToKey])) {
|
||||
continue;
|
||||
}
|
||||
if ($nextKey === $jumpToKey) {
|
||||
continue 2;
|
||||
}
|
||||
$nextCase = $switch->cases[$jumpToKey];
|
||||
unset($switch->cases[$jumpToKey]);
|
||||
$insertByKeys[$key][] = $nextCase;
|
||||
|
@ -119,21 +114,11 @@ CODE_SAMPLE
|
|||
private function insertCaseByKeys(Switch_ $switch, array $insertByKeys) : void
|
||||
{
|
||||
foreach ($insertByKeys as $key => $insertByKey) {
|
||||
$switch->cases[$key]->stmts = [];
|
||||
$nextKey = $key + 1;
|
||||
\array_splice($switch->cases, $nextKey, 0, $insertByKey);
|
||||
}
|
||||
}
|
||||
private function cleanUpEqualCaseStmts(Switch_ $switch) : void
|
||||
{
|
||||
/** @var Case_|null $previousCase */
|
||||
$previousCase = null;
|
||||
foreach ($switch->cases as $case) {
|
||||
if ($previousCase instanceof Case_ && $this->areSwitchStmtsEqualsAndWithBreak($case, $previousCase)) {
|
||||
$previousCase->stmts = [];
|
||||
$this->hasChanged = \true;
|
||||
for ($jumpToKey = $key; $jumpToKey < $key + \count($insertByKey); ++$jumpToKey) {
|
||||
$switch->cases[$jumpToKey]->stmts = [];
|
||||
}
|
||||
$previousCase = $case;
|
||||
}
|
||||
}
|
||||
private function areSwitchStmtsEqualsAndWithBreak(Case_ $currentCase, Case_ $nextCase) : bool
|
||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '3f2fb29fe87904d779fb2f8d3e59492aaa9249f4';
|
||||
public const PACKAGE_VERSION = 'c61d8ea90edb04550b6a43f40bd6c6105a997189';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-11-10 05:04:21';
|
||||
public const RELEASE_DATE = '2023-11-10 05:53:14';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue