[CodeQuality] Remove unnecessary check next return removed no SimplifyIfElseToTernaryRector (#2457)

This commit is contained in:
Abdul Malik Ikhsan 2022-06-09 13:02:39 +07:00 committed by GitHub
parent 6c8b3dc9f8
commit 17b86d4b77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 0 additions and 30 deletions

View File

@ -12,10 +12,8 @@ use PhpParser\Node\Expr\Ternary;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Return_;
use Rector\Core\Contract\PhpParser\NodePrinterInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@ -126,40 +124,12 @@ CODE_SAMPLE
return null;
}
if ($this->isNextReturnRemoved($node, $ifAssignVar)) {
return null;
}
$expression = new Expression($assign);
$this->mirrorComments($expression, $node);
return $expression;
}
private function isNextReturnRemoved(If_ $if, Expr $expr): bool
{
if (! $this->nodesToRemoveCollector->isActive()) {
return false;
}
$next = $if->getAttribute(AttributeKey::NEXT_NODE);
if ($next instanceof Return_ && $next->expr instanceof Expr && $this->nodeComparator->areNodesEqual(
$next->expr,
$expr
)) {
$nodesToRemove = $this->nodesToRemoveCollector->getNodesToRemove();
foreach ($nodesToRemove as $nodeToRemove) {
if ($this->nodeComparator->areNodesEqual($next, $nodeToRemove)) {
return true;
}
}
}
return false;
}
/**
* @param Stmt[] $stmts
*/