[CodingStyle] remove extra break from BinarySwitchToIfElseRector

This commit is contained in:
Tomas Votruba 2019-08-01 14:09:18 +02:00
parent f1decfd723
commit 5a0258cc55
3 changed files with 40 additions and 1 deletions

View File

@ -95,7 +95,7 @@ CODE_SAMPLE
$ifNode->elseifs[] = new ElseIf_($equalNode, $this->removeBreakNodes($secondCase->stmts));
} else {
// defaults
$ifNode->else = new Else_($secondCase->stmts);
$ifNode->else = new Else_($this->removeBreakNodes($secondCase->stmts));
}
return $ifNode;

View File

@ -13,6 +13,7 @@ final class BinarySwitchToIfElseRectorTest extends AbstractRectorTestCase
__DIR__ . '/Fixture/fixture.php.inc',
__DIR__ . '/Fixture/in_class.php.inc',
__DIR__ . '/Fixture/if_or.php.inc',
__DIR__ . '/Fixture/extra_break.php.inc',
]);
}

View File

@ -0,0 +1,38 @@
<?php
namespace Rector\CodingStyle\Tests\Rector\Switch_\BinarySwitchToIfElseRector;
final class ExtraBreak
{
public function run($meal)
{
switch ($meal) {
case 'morning-food':
$food = 'small chicken';
break;
default:
$food = 'chicken';
break;
}
}
}
?>
-----
<?php
namespace Rector\CodingStyle\Tests\Rector\Switch_\BinarySwitchToIfElseRector;
final class ExtraBreak
{
public function run($meal)
{
if ($meal == 'morning-food') {
$food = 'small chicken';
} else {
$food = 'chicken';
}
}
}
?>