-
-
Notifications
You must be signed in to change notification settings - Fork 698
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DeadCode][WIP] Fixes #4925 Add RemoveDeadConditionAboveReturnRector
- Loading branch information
1 parent
7f3cfd9
commit 2c1c6eb
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
rules/dead-code/src/Rector/Return_/RemoveDeadConditionAboveReturnRector.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,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\DeadCode\Rector\Return_; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Stmt\Return_; | ||
use PHPStan\Type\Constant\ConstantBooleanType; | ||
use Rector\Core\Rector\AbstractRector; | ||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; | ||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
|
||
/** | ||
* @see \Rector\DeadCode\Tests\Rector\Return_\RemoveDeadConditionAboveReturnRector\RemoveDeadConditionAboveReturnRectorTest | ||
*/ | ||
final class RemoveDeadConditionAboveReturnRector extends AbstractRector | ||
{ | ||
public function getRuleDefinition(): RuleDefinition | ||
{ | ||
return new RuleDefinition('Remove dead condition above return', [ | ||
new CodeSample( | ||
<<<'CODE_SAMPLE' | ||
final class SomeClass | ||
{ | ||
public function go() | ||
{ | ||
if (1 === 1) { | ||
return 'yes'; | ||
} | ||
return 'yes'; | ||
} | ||
} | ||
CODE_SAMPLE | ||
, | ||
<<<'CODE_SAMPLE' | ||
final class SomeClass | ||
{ | ||
public function go() | ||
{ | ||
return 'yes'; | ||
} | ||
} | ||
CODE_SAMPLE | ||
), | ||
]); | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getNodeTypes(): array | ||
{ | ||
return [Return_::class]; | ||
} | ||
|
||
/** | ||
* @param Return_ $node | ||
*/ | ||
public function refactor(Node $node): ?Node | ||
{ | ||
return $node; | ||
} | ||
} |