-
-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Php80] Fix multiple cases and case mix up default for ChangeSwitchTo…
…MatchRector (#231) Co-authored-by: Do Pham Tuan <dptuan.itiu@gmail.com>
- Loading branch information
1 parent
bad9871
commit 5157414
Showing
4 changed files
with
103 additions
and
10 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
...tests/Php80/Rector/Switch_/ChangeSwitchToMatchRector/Fixture/cases_mix_up_default.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Switch_\ChangeSwitchToMatchRector\Fixture; | ||
|
||
class CasesMixUpDefault | ||
{ | ||
public function run($value) | ||
{ | ||
switch ($value) { | ||
case 'foo': | ||
$string = 'foo'; | ||
break; | ||
case 'other': | ||
default: | ||
$string = 'bar'; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Switch_\ChangeSwitchToMatchRector\Fixture; | ||
|
||
class CasesMixUpDefault | ||
{ | ||
public function run($value) | ||
{ | ||
$string = match ($value) { | ||
'foo' => 'foo', | ||
default => 'bar', | ||
}; | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
rules-tests/Php80/Rector/Switch_/ChangeSwitchToMatchRector/Fixture/mutiple_cases2.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Switch_\ChangeSwitchToMatchRector\Fixture; | ||
|
||
final class MultipleCases2 | ||
{ | ||
public function run($value) | ||
{ | ||
switch ($value) { | ||
case 'v1': | ||
case 'v2': | ||
case 'v3': | ||
return 100; | ||
case 'v4': | ||
case 'v5': | ||
case 'v6': | ||
return 200; | ||
default: | ||
return 1000; | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Switch_\ChangeSwitchToMatchRector\Fixture; | ||
|
||
final class MultipleCases2 | ||
{ | ||
public function run($value) | ||
{ | ||
return match ($value) { | ||
'v1', 'v2', 'v3' => 100, | ||
'v4', 'v5', 'v6' => 200, | ||
default => 1000, | ||
}; | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters