Skip to content

Commit

Permalink
Updated Rector to commit eac58be00246ea8c89548289f2cc742e8b1b6b1a
Browse files Browse the repository at this point in the history
rectorphp/rector-src@eac58be [DeadCode] Reduce loop on RemoveDuplicatedCaseInSwitchRector (#5238)
  • Loading branch information
TomasVotruba committed Nov 10, 2023
1 parent 17eadc7 commit 382d51d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,14 @@ private function resolveInsertedByKeys(Switch_ $switch) : array
$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;
Expand All @@ -118,20 +122,13 @@ private function insertCaseByKeys(Switch_ $switch, array $insertByKeys) : void
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) {
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 = '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
*/
Expand Down

0 comments on commit 382d51d

Please sign in to comment.