Skip to content

Commit

Permalink
[CodeQuality] Remove next attribute usage on SimplifyIfNullableReturn…
Browse files Browse the repository at this point in the history
…Rector (#3866)

* [CodeQuality] Remove next attribute usage on SimplifyIfNullableReturnRector

* clean up

* [ci-review] Rector Rectify

---------

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
samsonasik and actions-user committed May 16, 2023
1 parent 5d78e95 commit 99bdd27
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PhpParser\Node\Expr\BooleanNot;
use PhpParser\Node\Expr\Instanceof_;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Return_;
Expand All @@ -22,7 +23,6 @@
use Rector\Core\NodeManipulator\IfManipulator;
use Rector\Core\Rector\AbstractRector;
use Rector\DeadCode\PhpDoc\TagRemover\VarTagRemover;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand Down Expand Up @@ -100,7 +100,7 @@ public function refactor(Node $node): ?Node
}

$if = $previousStmt;
if ($this->shouldSkip($if)) {
if ($this->shouldSkip($if, $stmt)) {
continue;
}

Expand Down Expand Up @@ -259,14 +259,13 @@ private function createDirectReturn(Expression $expression, Expr $expr, UnionTyp
return $exprReturn;
}

private function shouldSkip(If_ $if): bool
private function shouldSkip(If_ $if, Stmt $stmt): bool
{
if (! $this->ifManipulator->isIfWithOnly($if, Return_::class)) {
return true;
}

$nextNode = $if->getAttribute(AttributeKey::NEXT_NODE);
if (! $nextNode instanceof Return_) {
if (! $stmt instanceof Return_) {
return true;
}

Expand Down

0 comments on commit 99bdd27

Please sign in to comment.