Skip to content

Commit

Permalink
Remove deep reindex on refresh scope node
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Dec 19, 2024
1 parent e5e2ba2 commit a1a9e50
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 33 deletions.
2 changes: 1 addition & 1 deletion rules/Php80/NodeFactory/MatchArmsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function createFromCondAndExprs(array $condAndExprs): array
$expr = $expr->expr;
}

/** @var list<Expr> $condExprs */
/** @var null|list<Expr> $condExprs */
$condExprs = $condAndExpr->getCondExprs();
$matchArms[] = new MatchArm($condExprs, $expr, [
AttributeKey::COMMENTS => $condAndExprs[$key]->getComments(),
Expand Down
6 changes: 5 additions & 1 deletion rules/Php80/ValueObject/CondAndExpr.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ public function getCondExprs(): array|null
return null;
}

return $this->condExprs;
if ($this->condExprs === null) {
return null;
}

return array_values($this->condExprs);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Application/ChangedNodeScopeRefresher.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public function refresh(Node $node, string $filePath, ?MutatingScope $mutatingSc
throw new ShouldNotHappenException($errorMessage);
}

NodeAttributeReIndexer::reIndexNodeAttributes($node);

$stmts = $this->resolveStmts($node);
$this->phpStanNodeScopeResolver->processNodes($stmts, $filePath, $mutatingScope);
}
Expand Down
5 changes: 0 additions & 5 deletions src/Application/NodeAttributeReIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ public static function reIndexNodeAttributes(Node $node): ?Node
return $node;
}

if ($node instanceof MatchArm && is_array($node->conds)) {
$node->conds = array_values($node->conds);
return $node;
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\NodeTypeResolver\PHPStan\Scope\Contract\NodeVisitor\ScopeResolverNodeVisitorInterface;
use Rector\PhpParser\Node\CustomNode\FileWithoutNamespace;
use Rector\PHPStan\NodeVisitor\ReIndexNodeAttributeVisitor;
use Rector\PHPStan\NodeVisitor\UnreachableStatementNodeVisitor;
use Rector\PHPStan\NodeVisitor\WrappedNodeRestoringNodeVisitor;
use Rector\Util\Reflection\PrivatesAccessor;
Expand Down Expand Up @@ -159,14 +158,6 @@ public function processNodes(

Assert::allIsInstanceOf($stmts, Stmt::class);

// on refresh, early reindex node attributes
// due to PHPStan doing printing internally on process nodes
// using reindex via NodeVisitor on purpose to ensure reindex happen even on deep node changed
if ($formerMutatingScope instanceof MutatingScope) {
$nodeTraverser = new NodeTraverser(new ReIndexNodeAttributeVisitor());
$stmts = $nodeTraverser->traverse($stmts);
}

$this->nodeTraverser->traverse($stmts);

$scope = $formerMutatingScope ?? $this->scopeFactory->createFromFile($filePath);
Expand Down
17 changes: 0 additions & 17 deletions src/PHPStan/NodeVisitor/ReIndexNodeAttributeVisitor.php

This file was deleted.

0 comments on commit a1a9e50

Please sign in to comment.