Skip to content

Commit

Permalink
[DeadCode][WIP] Fixes #4925 Add RemoveDeadConditionAboveReturnRector
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Jan 15, 2021
1 parent 7f3cfd9 commit 2c1c6eb
Showing 1 changed file with 65 additions and 0 deletions.
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;
}
}

0 comments on commit 2c1c6eb

Please sign in to comment.