-
-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Php52][Php70] Handle ContinueToBreakInSwitchRector + BreakNotInLoopO…
…rSwitchToReturnRector (#5217) * [Php52][Php70] Handle ContinueToBreakInSwitchRector + BreakNotInLoopOrSwitchToReturnRector * Fixed 🎉 * Fixed 🎉 * Fixed 🎉 * Fixed 🎉 * rollback RectifiedAnalyzer * Fix
- Loading branch information
1 parent
95d0331
commit 0d55d15
Showing
4 changed files
with
96 additions
and
3 deletions.
There are no files selected for viewing
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
28 changes: 28 additions & 0 deletions
28
tests/Issues/ContinueToBreakSwitch/ContinueToBreakSwitchTest.php
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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Tests\Issues\ContinueToBreakSwitch; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class ContinueToBreakSwitchTest extends AbstractRectorTestCase | ||
{ | ||
#[DataProvider('provideData')] | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public static function provideData(): Iterator | ||
{ | ||
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
tests/Issues/ContinueToBreakSwitch/Fixture/fixture.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,49 @@ | ||
<?php | ||
|
||
namespace Rector\Core\Tests\Issues\ContinueToBreakSwitch\Fixture; | ||
|
||
final class Fixture | ||
{ | ||
public function process() { | ||
while ($something = \random_int(0, 4)) { | ||
switch ($something) { | ||
case 1: | ||
return $something; | ||
case 2: | ||
continue; | ||
default: | ||
\error_log('error'); | ||
throw new \Exception('error'); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Core\Tests\Issues\ContinueToBreakSwitch\Fixture; | ||
|
||
final class Fixture | ||
{ | ||
public function process() { | ||
while ($something = \random_int(0, 4)) { | ||
switch ($something) { | ||
case 1: | ||
return $something; | ||
case 2: | ||
break; | ||
default: | ||
\error_log('error'); | ||
throw new \Exception('error'); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
|
||
?> |
14 changes: 14 additions & 0 deletions
14
tests/Issues/ContinueToBreakSwitch/config/configured_rule.php
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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\Php52\Rector\Switch_\ContinueToBreakInSwitchRector; | ||
use Rector\Php70\Rector\Break_\BreakNotInLoopOrSwitchToReturnRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->rules([ | ||
BreakNotInLoopOrSwitchToReturnRector::class, | ||
ContinueToBreakInSwitchRector::class, | ||
]); | ||
}; |