-
-
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.
[Privatization] Skip ChangeReadOnlyVariableWithDefaultValueToConstant…
…Rector when local variable never used (#1693) * [Privatization] Skip ChangeReadOnlyVariableWithDefaultValueToConstantRector when local variable never used * [ci-review] Rector Rectify * Fixed 🎉 * [ci-review] Rector Rectify * [ci-review] Rector Rectify * phpstan * final touch: add test for combine ChangeReadOnlyVariableWithDefaultValueToConstantRector+RemoveUnusedVariableAssignRector * final touch: using array_filter like in other method Co-authored-by: GitHub Action <action@github.com>
- Loading branch information
1 parent
bf2f6dd
commit 1c7460b
Showing
6 changed files
with
112 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
14 changes: 14 additions & 0 deletions
14
...eReadOnlyVariableWithDefaultValueToConstantRector/Fixture/skip_defined_never_used.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,14 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Privatization\Rector\Class_\ChangeReadOnlyVariableWithDefaultValueToConstantRector\Fixture; | ||
|
||
class SkipDefinedNeverUsed | ||
{ | ||
public function run() | ||
{ | ||
$replacements = [ | ||
'PHPUnit\Framework\TestCase\Notice' => 'expectNotice', | ||
'PHPUnit\Framework\TestCase\Deprecated' => 'expectDeprecation', | ||
]; | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
tests/Issues/RemoveReadonlyLocalVariable/Fixture/remove_variable_assign_only.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,29 @@ | ||
<?php | ||
|
||
namespace Rector\Core\Tests\Issues\RemoveReadonlyLocalVariable\Fixture; | ||
|
||
final class RemoveVariableAssignOnly | ||
{ | ||
public function run() | ||
{ | ||
$replacements = [ | ||
'PHPUnit\Framework\TestCase\Notice' => 'expectNotice', | ||
'PHPUnit\Framework\TestCase\Deprecated' => 'expectDeprecation', | ||
]; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Core\Tests\Issues\RemoveReadonlyLocalVariable\Fixture; | ||
|
||
final class RemoveVariableAssignOnly | ||
{ | ||
public function run() | ||
{ | ||
} | ||
} | ||
|
||
?> |
33 changes: 33 additions & 0 deletions
33
tests/Issues/RemoveReadonlyLocalVariable/RemoveReadonlyLocalVariableTest.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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Tests\Issues\RemoveReadonlyLocalVariable; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class RemoveReadonlyLocalVariableTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(SmartFileInfo $fileInfo): void | ||
{ | ||
$this->doTestFileInfo($fileInfo); | ||
} | ||
|
||
/** | ||
* @return Iterator<SmartFileInfo> | ||
*/ | ||
public function provideData(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/Issues/RemoveReadonlyLocalVariable/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\DeadCode\Rector\Assign\RemoveUnusedVariableAssignRector; | ||
use Rector\Privatization\Rector\Class_\ChangeReadOnlyVariableWithDefaultValueToConstantRector; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
||
return static function (ContainerConfigurator $containerConfigurator): void { | ||
$services = $containerConfigurator->services(); | ||
$services->set(ChangeReadOnlyVariableWithDefaultValueToConstantRector::class); | ||
$services->set(RemoveUnusedVariableAssignRector::class); | ||
}; |