Skip to content

Commit 7f4fd54

Browse files
authored
avoid spl_object_id() if no change in AbstractRector (#7653)
1 parent fde2667 commit 7f4fd54

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

src/Application/NodeAttributeReIndexer.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,6 @@
2525

2626
final class NodeAttributeReIndexer
2727
{
28-
private static function reIndexStmtsKeys(Node $node): ?Node
29-
{
30-
if (! $node instanceof StmtsAwareInterface && ! $node instanceof ClassLike && ! $node instanceof Declare_ && ! $node instanceof Block) {
31-
return null;
32-
}
33-
34-
if ($node->stmts === null) {
35-
return null;
36-
}
37-
38-
$node->stmts = array_values($node->stmts);
39-
40-
return $node;
41-
}
42-
4328
public static function reIndexNodeAttributes(Node $node): ?Node
4429
{
4530
self::reIndexStmtsKeys($node);
@@ -78,4 +63,19 @@ public static function reIndexNodeAttributes(Node $node): ?Node
7863

7964
return null;
8065
}
66+
67+
private static function reIndexStmtsKeys(Node $node): ?Node
68+
{
69+
if (! $node instanceof StmtsAwareInterface && ! $node instanceof ClassLike && ! $node instanceof Declare_ && ! $node instanceof Block) {
70+
return null;
71+
}
72+
73+
if ($node->stmts === null) {
74+
return null;
75+
}
76+
77+
$node->stmts = array_values($node->stmts);
78+
79+
return $node;
80+
}
8181
}

src/Rector/AbstractRector.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ final public function leaveNode(Node $node): array|int|Node|null
196196
return null;
197197
}
198198

199+
// nothing to change here
200+
if ($this->toBeRemovedNodeId === null && $this->nodesToReturn === []) {
201+
return null;
202+
}
203+
199204
$objectId = spl_object_id($node);
200205
if ($this->toBeRemovedNodeId === $objectId) {
201206
$this->toBeRemovedNodeId = null;

0 commit comments

Comments
 (0)