@@ -96,36 +96,18 @@ private function compareUseStatements(UseStatement $a, UseStatement $b): int
9696 if (!$ a ->hasSameType ($ b )) {
9797 return $ a ->compareByType ($ b );
9898 }
99- $ aName = $ a ->getFullyQualifiedTypeName ();
100- $ bName = $ b ->getFullyQualifiedTypeName ();
101-
102- $ i = 0 ;
103- for (; $ i < min (strlen ($ aName ), strlen ($ bName )); $ i ++) {
104- if ($ this ->isSpecialCharacter ($ aName [$ i ]) && !$ this ->isSpecialCharacter ($ bName [$ i ])) {
105- return -1 ;
106- } elseif (!$ this ->isSpecialCharacter ($ aName [$ i ]) && $ this ->isSpecialCharacter ($ bName [$ i ])) {
107- return 1 ;
108- }
10999
110- if (is_numeric ($ aName [$ i ]) && is_numeric ($ bName [$ i ])) {
111- break ;
112- }
100+ $ aNameParts = explode (NamespaceHelper::NAMESPACE_SEPARATOR , $ a ->getFullyQualifiedTypeName ());
101+ $ bNameParts = explode (NamespaceHelper::NAMESPACE_SEPARATOR , $ b ->getFullyQualifiedTypeName ());
113102
114- $ cmp = strcasecmp ($ aName [$ i ], $ bName [$ i ]);
115- if (
116- $ cmp !== 0
117- || ($ aName [$ i ] !== $ bName [$ i ] && strtolower ($ aName [$ i ]) === strtolower ($ bName [$ i ]))
118- ) {
119- return $ cmp ;
103+ for ($ i = 0 ; $ i < min (count ($ aNameParts ), count ($ bNameParts )); $ i ++) {
104+ $ comparison = strcasecmp ($ aNameParts [$ i ], $ bNameParts [$ i ]);
105+ if ($ comparison !== 0 ) {
106+ return $ comparison ;
120107 }
121108 }
122109
123- return strnatcasecmp (substr ($ aName , $ i ), substr ($ bName , $ i ));
124- }
125-
126- private function isSpecialCharacter (string $ character ): bool
127- {
128- return in_array ($ character , ['\\' , '_ ' ], true );
110+ return count ($ aNameParts ) <=> count ($ bNameParts );
129111 }
130112
131113}
0 commit comments