Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NodeTypeResolver] Reduce parent attribute usage on PHPStanNodeScopeResolver #3943

Merged
merged 3 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use PhpParser\Node\Expr\AssignOp;
use PhpParser\Node\Expr\BinaryOp;
use PhpParser\Node\Expr\Cast;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Ternary;
use PhpParser\Node\Expr\Variable;
Expand Down Expand Up @@ -47,7 +46,6 @@
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\NodeAnalyzer\ClassAnalyzer;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Util\Reflection\PrivatesAccessor;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\Node\AttributeKey;
Expand Down Expand Up @@ -79,7 +77,6 @@ public function __construct(
private readonly ScopeFactory $scopeFactory,
private readonly PrivatesAccessor $privatesAccessor,
private readonly NodeNameResolver $nodeNameResolver,
private readonly BetterNodeFinder $betterNodeFinder,
private readonly ClassAnalyzer $classAnalyzer
) {
$this->nodeTraverser = new NodeTraverser();
Expand Down Expand Up @@ -236,25 +233,20 @@ public function processNodes(

private function setChildOfUnreachableStatementNodeAttribute(Stmt $stmt): void
{
if ($stmt->getAttribute(AttributeKey::IS_UNREACHABLE) === true) {
if ($stmt->getAttribute(AttributeKey::IS_UNREACHABLE) !== true) {
return;
}

$parentStmt = $stmt->getAttribute(AttributeKey::PARENT_NODE);
if (! $parentStmt instanceof Node) {
if (! $stmt instanceof StmtsAwareInterface) {
return;
}

if ($parentStmt instanceof Closure) {
$parentStmt = $this->betterNodeFinder->resolveCurrentStatement($parentStmt);
}

if (! $parentStmt instanceof Stmt) {
if ($stmt->stmts === null) {
return;
}

if ($parentStmt->getAttribute(AttributeKey::IS_UNREACHABLE) === true) {
$stmt->setAttribute(AttributeKey::IS_UNREACHABLE, true);
foreach ($stmt->stmts as $childStmt) {
$childStmt->setAttribute(AttributeKey::IS_UNREACHABLE, true);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/RectorKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class RectorKernel
/**
* @var string
*/
private const CACHE_KEY = 'v24';
private const CACHE_KEY = 'v25';

private ContainerInterface|null $container = null;

Expand Down