Skip to content

Commit

Permalink
[EarlyReturn][Php80] Fix used along tweak between Php8ResourceReturnT…
Browse files Browse the repository at this point in the history
…oObjectRector+ChangeOrIfReturnToEarlyReturnRector (#1984)
  • Loading branch information
samsonasik committed Apr 1, 2022
1 parent 12f027c commit 3596755
Showing 1 changed file with 1 addition and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp;
use PhpParser\Node\Expr\BinaryOp\BooleanOr;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Instanceof_;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Return_;
Expand Down Expand Up @@ -93,11 +92,6 @@ public function refactor(Node $node): ?array
return null;
}

// maybe used along with Php8ResourceReturnToObjectRector rule
if ($this->isMaybeUsedAlongWithResourceToObjectRector($node->cond)) {
return null;
}

/** @var Return_ $return */
$return = $node->stmts[0];

Expand All @@ -118,27 +112,6 @@ public function refactor(Node $node): ?array
return $ifs;
}

private function isMaybeUsedAlongWithResourceToObjectRector(BooleanOr $booleanOr): bool
{
if ($booleanOr->left instanceof FuncCall) {
if (! $this->nodeNameResolver->isName($booleanOr->left, 'is_resource')) {
return false;
}

return $booleanOr->right instanceof Instanceof_;
}

if ($booleanOr->right instanceof FuncCall) {
if (! $this->nodeNameResolver->isName($booleanOr->right, 'is_resource')) {
return false;
}

return $booleanOr->left instanceof Instanceof_;
}

return false;
}

/**
* @param If_[] $ifs
* @return If_[]
Expand Down Expand Up @@ -189,6 +162,6 @@ private function isInstanceofCondOnly(BooleanOr|BinaryOp $booleanOr): bool
return $this->isInstanceofCondOnly($booleanOr->right);
}

return $booleanOr->right instanceof Instanceof_;
return $booleanOr->left instanceof Instanceof_ || $booleanOr->right instanceof Instanceof_;
}
}

0 comments on commit 3596755

Please sign in to comment.