Skip to content
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
9 changes: 4 additions & 5 deletions rules/DeadCode/Rector/Assign/RemoveDoubleAssignRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,22 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
$stmts = $node->stmts;
if ($stmts === null) {
if ($node->stmts === null) {
return null;
}

$hasChanged = false;

foreach ($stmts as $key => $stmt) {
if (! isset($stmts[$key + 1])) {
foreach ($node->stmts as $key => $stmt) {
if (! isset($node->stmts[$key + 1])) {
continue;
}

if (! $stmt instanceof Expression) {
continue;
}

$nextStmt = $stmts[$key + 1];
$nextStmt = $node->stmts[$key + 1];
if (! $nextStmt instanceof Expression) {
continue;
}
Expand Down
1 change: 1 addition & 0 deletions src/Application/NodeAttributeReIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static function reIndexStmtsKeys(Node $node): ?Node
}

$node->stmts = array_values($node->stmts);

return $node;
}

Expand Down
2 changes: 0 additions & 2 deletions src/DependencyInjection/LazyContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\GlobalVariableNodeVisitor;
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\NameNodeVisitor;
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\StaticVariableNodeVisitor;
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\StmtKeyNodeVisitor;
use Rector\NodeTypeResolver\PHPStan\Scope\PHPStanNodeScopeResolver;
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider;
use Rector\Php80\AttributeDecorator\DoctrineConverterAttributeDecorator;
Expand Down Expand Up @@ -243,7 +242,6 @@ final class LazyContainerFactory
GlobalVariableNodeVisitor::class,
NameNodeVisitor::class,
StaticVariableNodeVisitor::class,
StmtKeyNodeVisitor::class,
];

/**
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions src/Rector/AbstractRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ final public function enterNode(Node $node): int|Node|null
// ensure origNode pulled before refactor to avoid changed during refactor, ref https://3v4l.org/YMEGN
$originalNode = $node->getAttribute(AttributeKey::ORIGINAL_NODE) ?? $node;

NodeAttributeReIndexer::reIndexNodeAttributes($node);

$refactoredNode = $this->refactor($node);

// nothing to change → continue
Expand All @@ -153,6 +151,8 @@ final public function enterNode(Node $node): int|Node|null
throw new ShouldNotHappenException($errorMessage);
}

NodeAttributeReIndexer::reIndexNodeAttributes($node);
Copy link
Member

@samsonasik samsonasik Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is called on ChangedNodeScopeRefresher::refresh() as well, see:

// reindex stmt_key already covered on StmtKeyNodeVisitor on next processNodes()
// so set flag $reIndexStmtKey to false to avoid double loop
NodeAttributeReIndexer::reIndexNodeAttributes($node, false);

while there disable sort order stmt keys.

Actually, possible bug may happen by only on after refactor, eg: when it returns remove node, which key is from parent, which means the order should be before processing as well, as next visitor may from parent, which the key not yet ordered.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the reindex needs on $refactoredNode, not a $node as it means before refactored.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally create a PR with failing test fixture on real rule we have, so we got it covered.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll investigate 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


$isIntRefactoredNode = is_int($refactoredNode);

/**
Expand Down