Updated Rector to commit eac58be00246ea8c89548289f2cc742e8b1b6b1a

eac58be002 [DeadCode] Reduce loop on RemoveDuplicatedCaseInSwitchRector (#5238)
This commit is contained in:
Tomas Votruba 2023-11-10 12:36:56 +00:00
parent 17eadc7eb2
commit 382d51d15f
2 changed files with 12 additions and 15 deletions

View File

@ -90,10 +90,14 @@ CODE_SAMPLE
$totalKeys = \count($switch->cases);
$insertByKeys = [];
$appendKey = 0;
/** @var Case_|null $previousCase */
$previousCase = null;
foreach ($switch->cases as $key => $case) {
if ($case->stmts === []) {
continue;
if ($previousCase instanceof Case_ && $this->areSwitchStmtsEqualsAndWithBreak($case, $previousCase)) {
$previousCase->stmts = [];
$this->hasChanged = \true;
}
$previousCase = $case;
for ($jumpToKey = $key + 2; $jumpToKey < $totalKeys; ++$jumpToKey) {
if (!isset($switch->cases[$jumpToKey])) {
continue;
@ -118,20 +122,13 @@ CODE_SAMPLE
foreach ($insertByKeys as $key => $insertByKey) {
$nextKey = $key + 1;
\array_splice($switch->cases, $nextKey, 0, $insertByKey);
}
/** @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;
$switch->cases[$key]->stmts = [];
$this->hasChanged = \true;
}
}
private function areSwitchStmtsEqualsAndWithBreak(Case_ $currentCase, Case_ $nextCase) : bool
private function areSwitchStmtsEqualsAndWithBreak(Case_ $currentCase, Case_ $nextOrPrevCase) : bool
{
if (!$this->nodeComparator->areNodesEqual($currentCase->stmts, $nextCase->stmts)) {
if (!$this->nodeComparator->areNodesEqual($currentCase->stmts, $nextOrPrevCase->stmts)) {
return \false;
}
foreach ($currentCase->stmts as $stmt) {

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'b0d4b15c3fd96582c6e3ed4d21cf4d30eb8742ce';
public const PACKAGE_VERSION = 'eac58be00246ea8c89548289f2cc742e8b1b6b1a';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-11-10 08:58:55';
public const RELEASE_DATE = '2023-11-10 19:34:50';
/**
* @var int
*/