88use PhpParser \Node \Name \FullyQualified ;
99use PhpParser \Node \Stmt \GroupUse ;
1010use PhpParser \Node \Stmt \Use_ ;
11- use PHPStan \Analyser \Scope ;
1211use Rector \CodingStyle \ClassNameImport \ClassNameImportSkipper ;
1312use Rector \Naming \Naming \AliasNameResolver ;
1413use Rector \NodeTypeResolver \Node \AttributeKey ;
@@ -91,11 +90,6 @@ private function importNameAndCollectNewUseStatement(File $file, FullyQualified
9190 $ nameInUse ->setAttribute (AttributeKey::NAMESPACED_NAME , $ fullyQualified ->toString ());
9291 return $ nameInUse ;
9392 }
94- $ nameInNamespacedScope = $ this ->resolveNameInNamespacedScope ($ fullyQualified );
95- if ($ nameInNamespacedScope instanceof Name) {
96- $ nameInNamespacedScope ->setAttribute (AttributeKey::NAMESPACED_NAME , $ fullyQualified ->toString ());
97- return $ nameInNamespacedScope ;
98- }
9993 // the same end is already imported → skip
10094 if ($ this ->classNameImportSkipper ->shouldSkipNameForFullyQualifiedObjectType ($ file , $ fullyQualified , $ fullyQualifiedObjectType )) {
10195 return null ;
@@ -109,29 +103,6 @@ private function importNameAndCollectNewUseStatement(File $file, FullyQualified
109103 $ this ->addUseImport ($ file , $ fullyQualified , $ fullyQualifiedObjectType );
110104 return $ fullyQualifiedObjectType ->getShortNameNode ();
111105 }
112- private function resolveNameInNamespacedScope (FullyQualified $ fullyQualified ): ?Name
113- {
114- /**
115- * Note: Don't use ScopeFetcher::fetch() on Name instance,
116- * Scope can be null on Name
117- * This is part of ScopeAnalyzer::NON_REFRESHABLE_NODES
118- * @see https://github.com/rectorphp/rector-src/blob/9929af7c0179929b4fde6915cb7a06c3141dde6c/src/NodeAnalyzer/ScopeAnalyzer.php#L17
119- */
120- $ scope = $ fullyQualified ->getAttribute (AttributeKey::SCOPE );
121- if (!$ scope instanceof Scope) {
122- return null ;
123- }
124- $ namespace = $ scope ->getNamespace ();
125- if ($ namespace === null ) {
126- return null ;
127- }
128- $ shortName = $ fullyQualified ->getLast ();
129- $ namepaceFullyQualifiedName = substr ($ fullyQualified ->toString (), 0 , -strlen ($ shortName ) - 1 );
130- if ($ namepaceFullyQualifiedName === $ namespace ) {
131- return new Name ($ shortName );
132- }
133- return null ;
134- }
135106 private function addUseImport (File $ file , FullyQualified $ fullyQualified , FullyQualifiedObjectType $ fullyQualifiedObjectType ): void
136107 {
137108 if ($ this ->useNodesToAddCollector ->hasImport ($ file , $ fullyQualified , $ fullyQualifiedObjectType )) {
0 commit comments