Skip to content

Commit

Permalink
[DeadCode] Skip multi no stmts on RemoveDuplicatedCaseInSwitchRector (#…
Browse files Browse the repository at this point in the history
…5258)

* [DeadCode] Handle multi no stmts on RemoveDuplicatedCaseInSwitchRector

* Fixed 🎉
  • Loading branch information
samsonasik committed Nov 18, 2023
1 parent 2d1b9ab commit 4a3e698
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
@@ -0,0 +1,27 @@
<?php

namespace Rector\Tests\DeadCode\Rector\Switch_\RemoveDuplicatedCaseInSwitchRector\Fixture;

class SkipMultiNoStmts
{
public function run($foo)
{
switch ($foo) {
default:
case 'A':
// Nothing to do
break;
case 'B':
case 'C':
// Nothing to do 2
break;
case 'D':
$type = 'BAR';
break;
case 'E':
case 'F':
// Nothing to do 3
break;
}
}
}
Expand Up @@ -98,6 +98,10 @@ private function removeDuplicatedCases(Switch_ $switch): void
{
$totalKeys = count($switch->cases);
foreach (array_keys($switch->cases) as $key) {
if (isset($switch->cases[$key - 1]) && $switch->cases[$key-1]->stmts === []) {
continue;
}

$nextCases = [];
for ($jumpToKey = $key + 1; $jumpToKey < $totalKeys; ++$jumpToKey) {
if (! isset($switch->cases[$jumpToKey])) {
Expand Down

0 comments on commit 4a3e698

Please sign in to comment.