File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -108,7 +108,29 @@ private function importNameAndCollectNewUseStatement(
108108 }
109109
110110 $ this ->addUseImport ($ file , $ fullyQualified , $ fullyQualifiedObjectType );
111- return $ fullyQualifiedObjectType ->getShortNameNode ();
111+ $ name = $ fullyQualifiedObjectType ->getShortNameNode ();
112+
113+ $ oldTokens = $ file ->getOldTokens ();
114+ $ startTokenPos = $ fullyQualified ->getStartTokenPos ();
115+
116+ if (! isset ($ oldTokens [$ startTokenPos ])) {
117+ return $ name ;
118+ }
119+
120+ $ tokenShortName = $ oldTokens [$ startTokenPos ];
121+ if (str_starts_with ($ tokenShortName ->text , '\\' )) {
122+ return $ name ;
123+ }
124+
125+ if (str_contains ($ tokenShortName ->text , '\\' )) {
126+ return $ name ;
127+ }
128+
129+ if ($ name ->toString () !== $ tokenShortName ->text ) {
130+ return $ name ;
131+ }
132+
133+ return null ;
112134 }
113135
114136 private function addUseImport (
You can’t perform that action at this time.
0 commit comments