Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DeadCode] Fix infinite loop on RemoveDeadStmtRector + RemoveUnusedVa…
…riableAssignRector (#5666)
- Loading branch information
1 parent
58abec4
commit a56ee1e
Showing
4 changed files
with
72 additions
and
2 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
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\Tests\Issues\InfiniteLoop; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class DeadStmtUnusedVariableTest extends AbstractRectorTestCase | ||
{ | ||
#[DataProvider('provideData')] | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public static function provideData(): Iterator | ||
{ | ||
return self::yieldFilesFromDirectory(__DIR__ . '/FixtureDeadStmtUnusedVariable'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/dead_stmt_unused_variable.php'; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
tests/Issues/InfiniteLoop/FixtureDeadStmtUnusedVariable/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,28 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\BooleanNot\SimplifyDeMorganBinaryRector\FixtureDeadStmtUnusedVariable; | ||
|
||
class X | ||
{ | ||
public function f() | ||
{ | ||
$var = $object->a() . $object->b(); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\BooleanNot\SimplifyDeMorganBinaryRector\FixtureDeadStmtUnusedVariable; | ||
|
||
class X | ||
{ | ||
public function f() | ||
{ | ||
$object->b(); | ||
$object->a(); | ||
} | ||
} | ||
|
||
?> |
13 changes: 13 additions & 0 deletions
13
tests/Issues/InfiniteLoop/config/dead_stmt_unused_variable.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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\DeadCode\Rector\Assign\RemoveUnusedVariableAssignRector; | ||
use Rector\DeadCode\Rector\Expression\RemoveDeadStmtRector; | ||
|
||
return RectorConfig::configure() | ||
->withRules([ | ||
RemoveDeadStmtRector::class, | ||
RemoveUnusedVariableAssignRector::class | ||
]); |