Skip to content

Commit

Permalink
Updated Rector to commit 99b6d309220f3cdda9f49cf8bf6bc21863b03c26
Browse files Browse the repository at this point in the history
rectorphp/rector-src@99b6d30 [NodeTypeResolver] Re-index node attributes on refresh scope process (#6601)
  • Loading branch information
TomasVotruba committed Dec 18, 2024
1 parent 3c22658 commit 2715075
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 50 deletions.
4 changes: 3 additions & 1 deletion rules/CodingStyle/Application/UseImportsRemover.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function __construct(RenamedNameCollector $renamedNameCollector)
*/
public function removeImportsFromStmts(array $stmts, array $removedUses) : array
{
$hasRemoved = \false;
foreach ($stmts as $key => $stmt) {
if (!$stmt instanceof Use_) {
continue;
Expand All @@ -31,9 +32,10 @@ public function removeImportsFromStmts(array $stmts, array $removedUses) : array
// remove empty uses
if ($stmt->uses === []) {
unset($stmts[$key]);
$hasRemoved = \true;
}
}
return $stmts;
return $hasRemoved ? \array_values($stmts) : $stmts;
}
/**
* @param string[] $removedUses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function refactor(Node $node) : ?Node
}
$originalArgs = $node->args;
unset($originalArgs[0]);
$methodCall->args = \array_values($originalArgs);
$methodCall->args = $originalArgs;
return $methodCall;
}
}
5 changes: 0 additions & 5 deletions rules/Php80/NodeFactory/MatchArmsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ public function createFromCondAndExprs(array $condAndExprs) : array
$condExprs = $condAndExpr->getCondExprs();
$matchArms[] = new MatchArm($condExprs, $expr, [AttributeKey::COMMENTS => $condAndExprs[$key]->getComments()]);
}
foreach ($matchArms as $matchArm) {
if (\is_array($matchArm->conds)) {
$matchArm->conds = \array_values($matchArm->conds);
}
}
return $matchArms;
}
}
35 changes: 0 additions & 35 deletions src/Application/ChangedNodeScopeRefresher.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,14 @@
use PhpParser\Node\DeclareItem;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\CallLike;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\NullsafeMethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\PropertyItem;
use PhpParser\Node\StaticVar;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Declare_;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Property;
use PhpParser\Node\Stmt\Static_;
use PhpParser\Node\Stmt\Switch_;
use PhpParser\Node\Stmt\TryCatch;
use PhpParser\Node\Stmt\Use_;
use PhpParser\Node\UseItem;
use PHPStan\Analyser\MutatingScope;
Expand Down Expand Up @@ -67,29 +55,6 @@ public function refresh(Node $node, string $filePath, ?MutatingScope $mutatingSc
$stmts = $this->resolveStmts($node);
$this->phpStanNodeScopeResolver->processNodes($stmts, $filePath, $mutatingScope);
}
public function reIndexNodeAttributes(Node $node) : void
{
if ($node instanceof FunctionLike) {
/** @var ClassMethod|Function_|Closure $node */
$node->params = \array_values($node->params);
if ($node instanceof Closure) {
$node->uses = \array_values($node->uses);
}
}
if ($node instanceof CallLike) {
/** @var FuncCall|MethodCall|New_|NullsafeMethodCall|StaticCall $node */
$node->args = \array_values($node->args);
}
if ($node instanceof If_) {
$node->elseifs = \array_values($node->elseifs);
}
if ($node instanceof TryCatch) {
$node->catches = \array_values($node->catches);
}
if ($node instanceof Switch_) {
$node->cases = \array_values($node->cases);
}
}
/**
* @return Stmt[]
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '6024d31dd6e946e3801436de95a1e2dcf64be7b2';
public const PACKAGE_VERSION = '99b6d309220f3cdda9f49cf8bf6bc21863b03c26';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-12-18 05:05:39';
public const RELEASE_DATE = '2024-12-18 10:44:57';
/**
* @var int
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
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 @@ -173,6 +174,13 @@ public function processNodes(array $stmts, string $filePath, ?MutatingScope $for
* @see vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php:282
*/
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);
$hasUnreachableStatementNode = \false;
Expand Down
57 changes: 57 additions & 0 deletions src/PHPStan/NodeVisitor/ReIndexNodeAttributeVisitor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare (strict_types=1);
namespace Rector\PHPStan\NodeVisitor;

use PhpParser\Node;
use PhpParser\Node\Expr\CallLike;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\NullsafeMethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\MatchArm;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Switch_;
use PhpParser\Node\Stmt\TryCatch;
use PhpParser\NodeVisitorAbstract;
final class ReIndexNodeAttributeVisitor extends NodeVisitorAbstract
{
public function enterNode(Node $node) : ?Node
{
if ($node instanceof CallLike) {
/** @var FuncCall|MethodCall|New_|NullsafeMethodCall|StaticCall $node */
$node->args = \array_values($node->args);
return $node;
}
if ($node instanceof FunctionLike) {
/** @var ClassMethod|Function_|Closure $node */
$node->params = \array_values($node->params);
if ($node instanceof Closure) {
$node->uses = \array_values($node->uses);
}
return $node;
}
if ($node instanceof If_) {
$node->elseifs = \array_values($node->elseifs);
return null;
}
if ($node instanceof TryCatch) {
$node->catches = \array_values($node->catches);
return $node;
}
if ($node instanceof Switch_) {
$node->cases = \array_values($node->cases);
return $node;
}
if ($node instanceof MatchArm && \is_array($node->conds)) {
$node->conds = \array_values($node->conds);
return $node;
}
return null;
}
}
1 change: 0 additions & 1 deletion src/Rector/AbstractRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public final function enterNode(Node $node)
if ($this->skipper->shouldSkipCurrentNode($this, $filePath, static::class, $node)) {
return null;
}
$this->changedNodeScopeRefresher->reIndexNodeAttributes($node);
// ensure origNode pulled before refactor to avoid changed during refactor, ref https://3v4l.org/YMEGN
$originalNode = $node->getAttribute(AttributeKey::ORIGINAL_NODE) ?? $node;
$refactoredNode = $this->refactor($node);
Expand Down
1 change: 1 addition & 0 deletions vendor/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1745,6 +1745,7 @@
'Rector\\PHPStanStaticTypeMapper\\TypeMapper\\UnionTypeMapper' => $baseDir . '/src/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php',
'Rector\\PHPStanStaticTypeMapper\\TypeMapper\\VoidTypeMapper' => $baseDir . '/src/PHPStanStaticTypeMapper/TypeMapper/VoidTypeMapper.php',
'Rector\\PHPStanStaticTypeMapper\\Utils\\TypeUnwrapper' => $baseDir . '/src/PHPStanStaticTypeMapper/Utils/TypeUnwrapper.php',
'Rector\\PHPStan\\NodeVisitor\\ReIndexNodeAttributeVisitor' => $baseDir . '/src/PHPStan/NodeVisitor/ReIndexNodeAttributeVisitor.php',
'Rector\\PHPStan\\NodeVisitor\\UnreachableStatementNodeVisitor' => $baseDir . '/src/PHPStan/NodeVisitor/UnreachableStatementNodeVisitor.php',
'Rector\\PHPStan\\NodeVisitor\\WrappedNodeRestoringNodeVisitor' => $baseDir . '/src/PHPStan/NodeVisitor/WrappedNodeRestoringNodeVisitor.php',
'Rector\\PHPStan\\ScopeFetcher' => $baseDir . '/src/PHPStan/ScopeFetcher.php',
Expand Down
1 change: 1 addition & 0 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -1964,6 +1964,7 @@ class ComposerStaticInite1459f150f08d0eee2804dfc37f818db
'Rector\\PHPStanStaticTypeMapper\\TypeMapper\\UnionTypeMapper' => __DIR__ . '/../..' . '/src/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php',
'Rector\\PHPStanStaticTypeMapper\\TypeMapper\\VoidTypeMapper' => __DIR__ . '/../..' . '/src/PHPStanStaticTypeMapper/TypeMapper/VoidTypeMapper.php',
'Rector\\PHPStanStaticTypeMapper\\Utils\\TypeUnwrapper' => __DIR__ . '/../..' . '/src/PHPStanStaticTypeMapper/Utils/TypeUnwrapper.php',
'Rector\\PHPStan\\NodeVisitor\\ReIndexNodeAttributeVisitor' => __DIR__ . '/../..' . '/src/PHPStan/NodeVisitor/ReIndexNodeAttributeVisitor.php',
'Rector\\PHPStan\\NodeVisitor\\UnreachableStatementNodeVisitor' => __DIR__ . '/../..' . '/src/PHPStan/NodeVisitor/UnreachableStatementNodeVisitor.php',
'Rector\\PHPStan\\NodeVisitor\\WrappedNodeRestoringNodeVisitor' => __DIR__ . '/../..' . '/src/PHPStan/NodeVisitor/WrappedNodeRestoringNodeVisitor.php',
'Rector\\PHPStan\\ScopeFetcher' => __DIR__ . '/../..' . '/src/PHPStan/ScopeFetcher.php',
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,8 @@
},
{
"name": "illuminate\/container",
"version": "v11.36.0",
"version_normalized": "11.36.0.0",
"version": "v11.36.1",
"version_normalized": "11.36.1.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/illuminate\/container.git",
Expand Down Expand Up @@ -569,8 +569,8 @@
},
{
"name": "illuminate\/contracts",
"version": "v11.36.0",
"version_normalized": "11.36.0.0",
"version": "v11.36.1",
"version_normalized": "11.36.1.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/illuminate\/contracts.git",
Expand Down
Loading

0 comments on commit 2715075

Please sign in to comment.