[EarlyReturn][Php80] Fix used along tweak between Php8ResourceReturnToObjectRector+ChangeOrIfReturnToEarlyReturnRector (#1984)

This commit is contained in:
Abdul Malik Ikhsan 2022-04-01 12:31:23 +07:00 committed by GitHub
parent 12f027c8a1
commit 3596755157
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,7 +8,6 @@ use PhpParser\Node;
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_;
@ -93,11 +92,6 @@ CODE_SAMPLE
return null;
}
// maybe used along with Php8ResourceReturnToObjectRector rule
if ($this->isMaybeUsedAlongWithResourceToObjectRector($node->cond)) {
return null;
}
/** @var Return_ $return */
$return = $node->stmts[0];
@ -118,27 +112,6 @@ CODE_SAMPLE
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_[]
@ -189,6 +162,6 @@ CODE_SAMPLE
return $this->isInstanceofCondOnly($booleanOr->right);
}
return $booleanOr->right instanceof Instanceof_;
return $booleanOr->left instanceof Instanceof_ || $booleanOr->right instanceof Instanceof_;
}
}