-
-
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.
[DeadCode][Php56] Handle infinite loop on RemoveUnusedVariableAssignR…
…ector+AddDefaultValueForUndefinedVariableRector (#3940) * [DeadCode][Php56] Handle infinite loop on RemoveUnusedVariableAssignRector+AddDefaultValueForUndefinedVariableRector * Fixed 🎉 * Fix
- Loading branch information
1 parent
5cd8ac7
commit e04e51c
Showing
5 changed files
with
76 additions
and
1 deletion.
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
24 changes: 24 additions & 0 deletions
24
tests/Issues/RemoveUnusedVariableDefault/Fixture/skip_use_static.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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Tests\Issues\RemoveUnusedVariableDefault\Fixture; | ||
|
||
class SkipUseStatic | ||
{ | ||
public static function showProgress($thisStep = 1, int $totalSteps = 10) | ||
{ | ||
static $inProgress = false; | ||
|
||
if ($inProgress !== false && $inProgress <= $thisStep) { | ||
static::fwrite(STDOUT, "\033[1A"); | ||
} | ||
$inProgress = $thisStep; | ||
|
||
if ($thisStep !== false) { | ||
$thisStep = abs($thisStep); | ||
} | ||
} | ||
} | ||
|
||
?> |
28 changes: 28 additions & 0 deletions
28
tests/Issues/RemoveUnusedVariableDefault/RemoveUnusedVariableDefaultTest.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\RemoveUnusedVariableDefault; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class RemoveUnusedVariableDefaultTest 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'; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/Issues/RemoveUnusedVariableDefault/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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\DeadCode\Rector\Assign\RemoveUnusedVariableAssignRector; | ||
use Rector\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector; | ||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->rules([ | ||
RemoveUnusedVariableAssignRector::class, | ||
AddDefaultValueForUndefinedVariableRector::class | ||
]); | ||
}; |