Skip to content

Commit 07cfc27

Browse files
authored
[Performance][AutoImport] Verify already use last name usage on long name on NameImportingPostRector (#6264)
1 parent 816c733 commit 07cfc27

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/PostRector/Rector/NameImportingPostRector.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ public function enterNode(Node $node): Node|int|null
5050
return null;
5151
}
5252

53+
// verify long name, as short name verify may conflict
54+
// see test PR: https://github.com/rectorphp/rector-src/pull/6208
55+
// ref https://3v4l.org/21H5j vs https://3v4l.org/GIHSB
56+
if (substr_count($node->toCodeString(), '\\') > 1) {
57+
$originalName = $node->getAttribute(AttributeKey::ORIGINAL_NAME);
58+
if ($originalName instanceof Name && $originalName->getLast() === $originalName->toString()) {
59+
return null;
60+
}
61+
}
62+
5363
if ($this->classNameImportSkipper->shouldSkipName($node, $this->currentUses)) {
5464
return null;
5565
}

src/PostRector/Rector/UnusedImportRemovingPostRector.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ private function findNonUseImportNames(Namespace_|FileWithoutNamespace $namespac
8989
return null;
9090
}
9191

92-
$names[] = $node->toString();
93-
9492
if ($node instanceof FullyQualified) {
9593
$originalName = $node->getAttribute(AttributeKey::ORIGINAL_NAME);
9694

9795
if ($originalName instanceof Name) {
98-
// collect original Name as well to cover namespaced used
96+
// collect original Name as cover namespaced used
9997
$names[] = $originalName->toString();
98+
return $node;
10099
}
101100
}
102101

102+
$names[] = $node->toString();
103103
return $node;
104104
});
105105

0 commit comments

Comments
 (0)