mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-18 09:02:26 +00:00
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;
|
$this->hasChanged = \false;
|
||||||
$insertByKeys = $this->resolveInsertedByKeys($node);
|
$insertByKeys = $this->resolveInsertedByKeys($node);
|
||||||
$this->insertCaseByKeys($node, $insertByKeys);
|
$this->insertCaseByKeys($node, $insertByKeys);
|
||||||
$this->cleanUpEqualCaseStmts($node);
|
|
||||||
if (!$this->hasChanged) {
|
if (!$this->hasChanged) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -94,7 +93,6 @@ CODE_SAMPLE
|
||||||
if ($case->stmts === []) {
|
if ($case->stmts === []) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$nextKey = $key + 1;
|
|
||||||
for ($jumpToKey = $key + 1; $jumpToKey < $totalKeys; ++$jumpToKey) {
|
for ($jumpToKey = $key + 1; $jumpToKey < $totalKeys; ++$jumpToKey) {
|
||||||
if (!isset($switch->cases[$jumpToKey])) {
|
if (!isset($switch->cases[$jumpToKey])) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -102,9 +100,6 @@ CODE_SAMPLE
|
||||||
if (!$this->areSwitchStmtsEqualsAndWithBreak($case, $switch->cases[$jumpToKey])) {
|
if (!$this->areSwitchStmtsEqualsAndWithBreak($case, $switch->cases[$jumpToKey])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ($nextKey === $jumpToKey) {
|
|
||||||
continue 2;
|
|
||||||
}
|
|
||||||
$nextCase = $switch->cases[$jumpToKey];
|
$nextCase = $switch->cases[$jumpToKey];
|
||||||
unset($switch->cases[$jumpToKey]);
|
unset($switch->cases[$jumpToKey]);
|
||||||
$insertByKeys[$key][] = $nextCase;
|
$insertByKeys[$key][] = $nextCase;
|
||||||
|
@ -119,21 +114,11 @@ CODE_SAMPLE
|
||||||
private function insertCaseByKeys(Switch_ $switch, array $insertByKeys) : void
|
private function insertCaseByKeys(Switch_ $switch, array $insertByKeys) : void
|
||||||
{
|
{
|
||||||
foreach ($insertByKeys as $key => $insertByKey) {
|
foreach ($insertByKeys as $key => $insertByKey) {
|
||||||
$switch->cases[$key]->stmts = [];
|
|
||||||
$nextKey = $key + 1;
|
$nextKey = $key + 1;
|
||||||
\array_splice($switch->cases, $nextKey, 0, $insertByKey);
|
\array_splice($switch->cases, $nextKey, 0, $insertByKey);
|
||||||
}
|
for ($jumpToKey = $key; $jumpToKey < $key + \count($insertByKey); ++$jumpToKey) {
|
||||||
}
|
$switch->cases[$jumpToKey]->stmts = [];
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
$previousCase = $case;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private function areSwitchStmtsEqualsAndWithBreak(Case_ $currentCase, Case_ $nextCase) : bool
|
private function areSwitchStmtsEqualsAndWithBreak(Case_ $currentCase, Case_ $nextCase) : bool
|
||||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const PACKAGE_VERSION = '3f2fb29fe87904d779fb2f8d3e59492aaa9249f4';
|
public const PACKAGE_VERSION = 'c61d8ea90edb04550b6a43f40bd6c6105a997189';
|
||||||
/**
|
/**
|
||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const RELEASE_DATE = '2023-11-10 05:04:21';
|
public const RELEASE_DATE = '2023-11-10 05:53:14';
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user