-
-
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.
[DeadCode][EarlyReturn] Handle RemoveUnusedVariableAssignRector + Rem…
…oveAlwaysElseRector (#1277) * [DeadCode][EarlyReturn] Handle RemoveUnusedVariableAssignRector + RemoveAlwaysElseRector * update fixture * eol * Fixed 🎉 * comment * Trigger notification * check in ExprUsedInNextNodeAnalyzer to handle error in parallel test * comment * clean up * phpstan * [ci-review] Rector Rectify * [ci-review] Rector Rectify * fix * move comment * [ci-review] Rector Rectify * Trigger notification * try 3 process * try 3 process Co-authored-by: GitHub Action <action@github.com>
- Loading branch information
1 parent
7acec2c
commit bc5462b
Showing
6 changed files
with
118 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
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
46 changes: 46 additions & 0 deletions
46
tests/Issues/RemoveUnusedVariableAlwaysElse/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,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Tests\Issues\RemoveUnusedVariableAlwaysElse\Fixture; | ||
|
||
final class Fixture | ||
{ | ||
public function run(Request $request) | ||
{ | ||
$path = $request->get('path', null); | ||
$url = $request->get('url', null); | ||
if (null !== $path) { | ||
return response()->file($path); | ||
} elseif (null !== $url) { | ||
return response()->getFile($url); | ||
} | ||
throw new \Exception('Error'); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Tests\Issues\RemoveUnusedVariableAlwaysElse\Fixture; | ||
|
||
final class Fixture | ||
{ | ||
public function run(Request $request) | ||
{ | ||
$path = $request->get('path', null); | ||
$url = $request->get('url', null); | ||
if (null !== $path) { | ||
return response()->file($path); | ||
} | ||
if (null !== $url) { | ||
return response()->getFile($url); | ||
} | ||
throw new \Exception('Error'); | ||
} | ||
} | ||
|
||
?> |
33 changes: 33 additions & 0 deletions
33
tests/Issues/RemoveUnusedVariableAlwaysElse/RemoveUnusedVariableAlwaysElseTest.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\RemoveUnusedVariableAlwaysElse; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class RemoveUnusedVariableAlwaysElseTest 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/RemoveUnusedVariableAlwaysElse/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\EarlyReturn\Rector\If_\RemoveAlwaysElseRector; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
||
return static function (ContainerConfigurator $containerConfigurator): void { | ||
$services = $containerConfigurator->services(); | ||
$services->set(RemoveUnusedVariableAssignRector::class); | ||
$services->set(RemoveAlwaysElseRector::class); | ||
}; |