@@ -96,19 +96,34 @@ private static function restructureImports(array $imports): array
9696 return $ imports ;
9797 }
9898
99- private static function deleteFQCN ($ absFilePath , $ classRef )
99+ public static function deleteFQCN ($ absFilePath , $ classRef )
100100 {
101101 $ line = $ classRef ['line ' ];
102102 $ classRef = $ classRef ['class ' ];
103103 $ lines = file ($ absFilePath );
104104 $ count = 0 ;
105- $ new = str_replace ($ classRef , basename ($ classRef ), $ lines [$ line - 1 ], $ count );
106105
106+ $ new = str_replace ([$ classRef ], basename ($ classRef ), $ lines [$ line - 1 ], $ count );
107107 if ($ count === 1 ) {
108108 $ lines [$ line - 1 ] = $ new ;
109+ file_put_contents ($ absFilePath , implode ('' , $ lines ));
110+
111+ return true ;
112+ } elseif ($ count > 1 ) {
113+ $ className = basename ($ classRef );
114+ $ search = [$ classRef .' ' , $ classRef .'( ' , $ classRef .':: ' , $ classRef .') ' , $ classRef .'; ' ];
115+ $ replace = [$ className .' ' , $ className .'( ' , $ className .':: ' , $ className .') ' , $ className .'; ' ];
116+
117+ $ new = str_replace ($ search , $ replace , $ lines [$ line - 1 ], $ count );
118+ if ($ count === 1 ) {
119+ $ lines [$ line - 1 ] = $ new ;
120+ file_put_contents ($ absFilePath , implode ('' , $ lines ));
121+
122+ return true ;
123+ }
109124 }
110125
111- file_put_contents ( $ absFilePath , implode ( '' , $ lines )) ;
126+ return false ;
112127 }
113128
114129 private static function reportAliasImported ($ absFilePath , $ alias , $ classRef )
0 commit comments