-
-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EarlyReturn] Handle crash on RemoveAlwaysElseRector+ReturnEarlyIfVar…
…iableRector (#3011) Co-authored-by: GitHub Action <action@github.com>
- Loading branch information
1 parent
f915a1f
commit 5131abd
Showing
4 changed files
with
107 additions
and
23 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
50 changes: 50 additions & 0 deletions
50
tests/Issues/IssueRemoveAlwaysElseReturnEarlyIfVariable/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,50 @@ | ||
<?php | ||
|
||
namespace Rector\Core\Tests\Issues\IssueRemoveAlwaysElseReturnEarlyIfVariable\Fixture; | ||
|
||
final class Fixture | ||
{ | ||
public function get($a, $b = false) | ||
{ | ||
if ($b !== true) { | ||
$value = $a * 5; | ||
|
||
if ($value === 'hello') { | ||
$value = false; | ||
} | ||
|
||
return $value; | ||
} elseif ($a === true) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Core\Tests\Issues\IssueRemoveAlwaysElseReturnEarlyIfVariable\Fixture; | ||
|
||
final class Fixture | ||
{ | ||
public function get($a, $b = false) | ||
{ | ||
if ($b !== true) { | ||
$value = $a * 5; | ||
if ($value === 'hello') { | ||
return false; | ||
} | ||
return $value; | ||
} | ||
if ($a === true) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
?> |
32 changes: 32 additions & 0 deletions
32
...eRemoveAlwaysElseReturnEarlyIfVariable/IssueRemoveAlwaysElseReturnEarlyIfVariableTest.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,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Tests\Issues\IssueRemoveAlwaysElseReturnEarlyIfVariable; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class IssueRemoveAlwaysElseReturnEarlyIfVariableTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
/** | ||
* @return Iterator<array<string>> | ||
*/ | ||
public function provideData(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/Issues/IssueRemoveAlwaysElseReturnEarlyIfVariable/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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector; | ||
use Rector\EarlyReturn\Rector\StmtsAwareInterface\ReturnEarlyIfVariableRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->rule(RemoveAlwaysElseRector::class); | ||
$rectorConfig->rule(ReturnEarlyIfVariableRector::class); | ||
}; |