Skip to content

Commit

Permalink
change coding-style
Browse files Browse the repository at this point in the history
  • Loading branch information
Khartir committed Aug 29, 2020
1 parent e66e988 commit 09e1619
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/Mutator/Removal/SharedCaseRemoval.php
Expand Up @@ -79,11 +79,11 @@ public function canMutate(Node $node): bool
*/
public function mutate(Node $node): iterable
{
$lastWasEmpty = false;
$previousWasEmpty = false;

foreach ($node->cases as $i => $case) {
if ($case->stmts === []) {
$lastWasEmpty = true;
$previousWasEmpty = true;
$cases = $node->cases;
unset($cases[$i]);

Expand All @@ -92,8 +92,10 @@ public function mutate(Node $node): iterable
$cases,
$node->getAttributes()
);
} elseif ($lastWasEmpty) {
$lastWasEmpty = false;
continue;
}
if ($previousWasEmpty) {
$previousWasEmpty = false;
$cases = $node->cases;
unset($cases[$i]);
$lastCase = $cases[$i - 1];
Expand Down
35 changes: 32 additions & 3 deletions tests/phpunit/Mutator/Removal/SharedCaseRemovalTest.php
Expand Up @@ -53,11 +53,30 @@ public function test_it_can_mutate(string $input, $expected = [], array $setting
public function mutationsProvider(): iterable
{
yield 'It does not mutate single cases with a body' => [
'<?php switch(true) {case true: $a = [];break; case false: $a = [];break;};',
'<?php
switch(true) {
case true:
$a = [];
break;
case false:
$a = [];
break;
}',
];

yield 'It removes cases that share a body' => [
'<?php switch(true) {case true: case false: $a = [];break; case null: $a = []; break;};',
'<?php
switch(true) {
case true:
case false:
$a = [];
break;
case null:
$a = [];
break;
}',
[
'<?php
Expand All @@ -83,7 +102,17 @@ public function mutationsProvider(): iterable
];

yield 'It removes default if it shares a body with a case' => [
'<?php switch(true) {case true: $a = [];break; case false: default: $b = []; break;};',
'<?php
switch(true) {
case true:
$a = [];
break;
case false:
default:
$b = [];
break;
}',
[
'<?php
Expand Down

0 comments on commit 09e1619

Please sign in to comment.