@@ -147,18 +147,10 @@ private function removeSingleUseStatements(array $statements, Tokens $tokens): v
147147 private function addGroupUseStatements (array $ statements , Tokens $ tokens ): void
148148 {
149149 $ currentUseDeclaration = null ;
150- $ insertIndex = \array_slice ($ statements , -1 )[0 ]->getEndIndex ();
151-
152- while ($ tokens [$ insertIndex ]->isGivenKind ([T_COMMENT , T_DOC_COMMENT ])) {
153- ++$ insertIndex ;
154- }
150+ $ insertIndex = \array_slice ($ statements , -1 )[0 ]->getEndIndex () + 1 ;
155151
156152 foreach ($ statements as $ index => $ useDeclaration ) {
157153 if ($ this ->areDeclarationsDifferent ($ currentUseDeclaration , $ useDeclaration )) {
158- if ($ index > 1 ) {
159- ++$ insertIndex ;
160- }
161-
162154 $ currentUseDeclaration = $ useDeclaration ;
163155 $ insertIndex += $ this ->createNewGroup (
164156 $ tokens ,
@@ -173,11 +165,11 @@ private function addGroupUseStatements(array $statements, Tokens $tokens): void
173165 ];
174166
175167 if ($ useDeclaration ->isAliased ()) {
176- $ tokens ->insertAt ($ insertIndex + 1 , $ newTokens );
168+ $ tokens ->insertAt ($ insertIndex , $ newTokens );
177169 $ insertIndex += \count ($ newTokens );
178170 $ newTokens = [];
179171
180- $ insertIndex += $ this ->insertToGroupUseWithAlias ($ tokens , $ insertIndex + 1 , $ useDeclaration );
172+ $ insertIndex += $ this ->insertToGroupUseWithAlias ($ tokens , $ insertIndex , $ useDeclaration );
181173 }
182174
183175 $ newTokens [] = new Token ([T_STRING , $ useDeclaration ->getShortName ()]);
@@ -188,7 +180,7 @@ private function addGroupUseStatements(array $statements, Tokens $tokens): void
188180 $ newTokens [] = new Token ([T_WHITESPACE , "\n" ]);
189181 }
190182
191- $ tokens ->insertAt ($ insertIndex + 1 , $ newTokens );
183+ $ tokens ->insertAt ($ insertIndex , $ newTokens );
192184 $ insertIndex += \count ($ newTokens );
193185 }
194186 }
@@ -218,7 +210,7 @@ private function insertToGroupUseWithAlias(Tokens $tokens, int $insertIndex, Nam
218210
219211 $ tokens ->insertAt ($ insertIndex , $ newTokens );
220212
221- return \count ($ newTokens );
213+ return \count ($ newTokens ) + 1 ;
222214 }
223215
224216 /**
@@ -267,7 +259,7 @@ private function createNewGroup(Tokens $tokens, int $insertIndex, NamespaceUseAn
267259 $ insertIndex += $ inserted ;
268260 }
269261
270- $ tokens ->insertAt ($ insertIndex + 1 , new Token ([T_STRING , $ useDeclaration ->getShortName ()]));
262+ $ tokens ->insertAt ($ insertIndex , new Token ([T_STRING , $ useDeclaration ->getShortName ()]));
271263 ++$ insertedTokens ;
272264
273265 return $ insertedTokens ;
0 commit comments