-
-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DeadCode][CodeQuality] Handle SimplifyIfElseToTernaryRector + Remove…
…UnusedAssignVariableRector (#789) Co-authored-by: Bl00D4NGEL <kuhlesdominik@gmx.de>
- Loading branch information
1 parent
a81fd4e
commit f257b10
Showing
4 changed files
with
78 additions
and
0 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,23 @@ | ||
<?php | ||
|
||
function getRes(): string | ||
{ | ||
if ('a' !== 'b') { | ||
$res = "a"; | ||
} else { | ||
$res = "b"; | ||
} | ||
|
||
return $res; | ||
} | ||
?> | ||
----- | ||
<?php | ||
|
||
function getRes(): string | ||
{ | ||
$res = 'a' !== 'b' ? "a" : "b"; | ||
|
||
return $res; | ||
} | ||
?> |
36 changes: 36 additions & 0 deletions
36
tests/Issues/Issue6655/SimplifyIfElseAndRemoveUnusedAssignVariableTest.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,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Tests\Issues\Issue6655; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
/** | ||
* @see https://github.com/rectorphp/rector/issues/6655 | ||
*/ | ||
final class SimplifyIfElseAndRemoveUnusedAssignVariableTest 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'; | ||
} | ||
} |
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 | ||
|
||
use Rector\DeadCode\Rector\Assign\RemoveUnusedAssignVariableRector; | ||
use Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
||
return static function (ContainerConfigurator $containerConfigurator): void { | ||
$services = $containerConfigurator->services(); | ||
|
||
$services->set(SimplifyIfElseToTernaryRector::class); | ||
$services->set(RemoveUnusedAssignVariableRector::class); | ||
}; |