@@ -161,13 +161,9 @@ protected function checkUseForAttribute(File $phpcsFile, int $stackPtr): void
161161 return ;
162162 }
163163
164- // PHP 8+: Check if it's T_NAME_FULLY_QUALIFIED or T_NAME_QUALIFIED token
165- if (
166- defined ('T_NAME_FULLY_QUALIFIED ' ) && (
167- $ this ->isGivenKind (T_NAME_FULLY_QUALIFIED , $ tokens [$ nextIndex ]) ||
168- $ this ->isGivenKind (T_NAME_QUALIFIED , $ tokens [$ nextIndex ])
169- )
170- ) {
164+ // PHP 8+: Check if it's a single T_NAME_FULLY_QUALIFIED token
165+ // Note: T_NAME_QUALIFIED (partial names) are not auto-fixed as we can't determine the full namespace
166+ if (defined ('T_NAME_FULLY_QUALIFIED ' ) && $ this ->isGivenKind (T_NAME_FULLY_QUALIFIED , $ tokens [$ nextIndex ])) {
171167 $ extractedUseStatement = ltrim ($ tokens [$ nextIndex ]['content ' ], '\\' );
172168 if (!str_contains ($ extractedUseStatement , '\\' )) {
173169 return ;
@@ -228,6 +224,12 @@ protected function fixStatement(File $phpcsFile, array $statement, int $stackPtr
228224 return ;
229225 }
230226
227+ // Skip partial FQCNs (not starting with \) as we can't determine the full namespace
228+ $ partial = !str_starts_with ($ statement ['content ' ], '\\' );
229+ if ($ partial ) {
230+ return ;
231+ }
232+
231233 $ extractedUseStatement = ltrim ($ statement ['content ' ], '\\' );
232234 $ className = substr ($ statement ['content ' ], strrpos ($ statement ['content ' ], '\\' ) + 1 );
233235
@@ -271,13 +273,9 @@ protected function checkUseForNew(File $phpcsFile, int $stackPtr): void
271273 return ;
272274 }
273275
274- // PHP 8+: Check if it's a single T_NAME_FULLY_QUALIFIED or T_NAME_QUALIFIED token
275- if (
276- defined ('T_NAME_FULLY_QUALIFIED ' ) && (
277- $ this ->isGivenKind (T_NAME_FULLY_QUALIFIED , $ tokens [$ nextIndex ]) ||
278- $ this ->isGivenKind (T_NAME_QUALIFIED , $ tokens [$ nextIndex ])
279- )
280- ) {
276+ // PHP 8+: Check if it's a single T_NAME_FULLY_QUALIFIED token
277+ // Note: T_NAME_QUALIFIED (partial names) are not auto-fixed as we can't determine the full namespace
278+ if (defined ('T_NAME_FULLY_QUALIFIED ' ) && $ this ->isGivenKind (T_NAME_FULLY_QUALIFIED , $ tokens [$ nextIndex ])) {
281279 $ extractedUseStatement = ltrim ($ tokens [$ nextIndex ]['content ' ], '\\' );
282280 if (!str_contains ($ extractedUseStatement , '\\' )) {
283281 return ;
@@ -389,13 +387,9 @@ protected function checkUseForStatic(File $phpcsFile, int $stackPtr): void
389387 return ;
390388 }
391389
392- // PHP 8+: Check if it's a single T_NAME_FULLY_QUALIFIED or T_NAME_QUALIFIED token
393- if (
394- defined ('T_NAME_FULLY_QUALIFIED ' ) && (
395- $ this ->isGivenKind (T_NAME_FULLY_QUALIFIED , $ tokens [$ prevIndex ]) ||
396- $ this ->isGivenKind (T_NAME_QUALIFIED , $ tokens [$ prevIndex ])
397- )
398- ) {
390+ // PHP 8+: Check if it's a single T_NAME_FULLY_QUALIFIED token
391+ // Note: T_NAME_QUALIFIED (partial names) are not auto-fixed as we can't determine the full namespace
392+ if (defined ('T_NAME_FULLY_QUALIFIED ' ) && $ this ->isGivenKind (T_NAME_FULLY_QUALIFIED , $ tokens [$ prevIndex ])) {
399393 $ extractedUseStatement = ltrim ($ tokens [$ prevIndex ]['content ' ], '\\' );
400394 if (!str_contains ($ extractedUseStatement , '\\' )) {
401395 return ;
@@ -499,13 +493,9 @@ protected function checkUseForInstanceOf(File $phpcsFile, int $stackPtr): void
499493 return ;
500494 }
501495
502- // PHP 8+: Check if it's a single T_NAME_FULLY_QUALIFIED or T_NAME_QUALIFIED token
503- if (
504- defined ('T_NAME_FULLY_QUALIFIED ' ) && (
505- $ this ->isGivenKind (T_NAME_FULLY_QUALIFIED , $ tokens [$ classNameIndex ]) ||
506- $ this ->isGivenKind (T_NAME_QUALIFIED , $ tokens [$ classNameIndex ])
507- )
508- ) {
496+ // PHP 8+: Check if it's a single T_NAME_FULLY_QUALIFIED token
497+ // Note: T_NAME_QUALIFIED (partial names) are not auto-fixed as we can't determine the full namespace
498+ if (defined ('T_NAME_FULLY_QUALIFIED ' ) && $ this ->isGivenKind (T_NAME_FULLY_QUALIFIED , $ tokens [$ classNameIndex ])) {
509499 $ extractedUseStatement = ltrim ($ tokens [$ classNameIndex ]['content ' ], '\\' );
510500 if (!str_contains ($ extractedUseStatement , '\\' )) {
511501 return ;
@@ -613,13 +603,9 @@ public function checkUseForCatchOrCallable(File $phpcsFile, int $stackPtr): void
613603 return ;
614604 }
615605
616- // PHP 8+: Check if it's a single T_NAME_FULLY_QUALIFIED or T_NAME_QUALIFIED token
617- if (
618- defined ('T_NAME_FULLY_QUALIFIED ' ) && (
619- $ this ->isGivenKind (T_NAME_FULLY_QUALIFIED , $ tokens [$ classNameIndex ]) ||
620- $ this ->isGivenKind (T_NAME_QUALIFIED , $ tokens [$ classNameIndex ])
621- )
622- ) {
606+ // PHP 8+: Check if it's a single T_NAME_FULLY_QUALIFIED token
607+ // Note: T_NAME_QUALIFIED (partial names) are not auto-fixed as we can't determine the full namespace
608+ if (defined ('T_NAME_FULLY_QUALIFIED ' ) && $ this ->isGivenKind (T_NAME_FULLY_QUALIFIED , $ tokens [$ classNameIndex ])) {
623609 $ extractedUseStatement = ltrim ($ tokens [$ classNameIndex ]['content ' ], '\\' );
624610 if (!str_contains ($ extractedUseStatement , '\\' )) {
625611 return ;
@@ -735,13 +721,9 @@ protected function checkUseForSignature(File $phpcsFile, int $stackPtr): void
735721 $ startIndex = $ i ;
736722 }
737723
738- // PHP 8+: Check if it's a single T_NAME_FULLY_QUALIFIED or T_NAME_QUALIFIED token
739- if (
740- defined ('T_NAME_FULLY_QUALIFIED ' ) && (
741- $ this ->isGivenKind (T_NAME_FULLY_QUALIFIED , $ tokens [$ i ]) ||
742- $ this ->isGivenKind (T_NAME_QUALIFIED , $ tokens [$ i ])
743- )
744- ) {
724+ // PHP 8+: Check if it's a single T_NAME_FULLY_QUALIFIED token
725+ // Note: T_NAME_QUALIFIED (partial names) are not auto-fixed as we can't determine the full namespace
726+ if (defined ('T_NAME_FULLY_QUALIFIED ' ) && $ this ->isGivenKind (T_NAME_FULLY_QUALIFIED , $ tokens [$ i ])) {
745727 $ extractedUseStatement = ltrim ($ tokens [$ i ]['content ' ], '\\' );
746728 if (!str_contains ($ extractedUseStatement , '\\' )) {
747729 continue ;
@@ -857,13 +839,9 @@ protected function checkUseForReturnTypeHint(File $phpcsFile, int $stackPtr): vo
857839 return ;
858840 }
859841
860- // PHP 8+: Check if it's a single T_NAME_FULLY_QUALIFIED or T_NAME_QUALIFIED token
861- if (
862- defined ('T_NAME_FULLY_QUALIFIED ' ) && (
863- $ this ->isGivenKind (T_NAME_FULLY_QUALIFIED , $ tokens [$ startIndex ]) ||
864- $ this ->isGivenKind (T_NAME_QUALIFIED , $ tokens [$ startIndex ])
865- )
866- ) {
842+ // PHP 8+: Check if it's a single T_NAME_FULLY_QUALIFIED token
843+ // Note: T_NAME_QUALIFIED (partial names) are not auto-fixed as we can't determine the full namespace
844+ if (defined ('T_NAME_FULLY_QUALIFIED ' ) && $ this ->isGivenKind (T_NAME_FULLY_QUALIFIED , $ tokens [$ startIndex ])) {
867845 $ extractedUseStatement = ltrim ($ tokens [$ startIndex ]['content ' ], '\\' );
868846 if (!str_contains ($ extractedUseStatement , '\\' )) {
869847 return ;
@@ -966,12 +944,10 @@ protected function checkPropertyForInstanceOf(File $phpcsFile, int $stackPtr): v
966944 return ;
967945 }
968946
969- // Handle T_NAME_FULLY_QUALIFIED or T_NAME_QUALIFIED token (PHP CodeSniffer v4)
947+ // Handle T_NAME_FULLY_QUALIFIED token (PHP CodeSniffer v4)
948+ // Note: T_NAME_QUALIFIED (partial names) are not auto-fixed as we can't determine the full namespace
970949 $ className = '' ;
971- if (
972- $ tokens [$ startIndex ]['code ' ] === T_NAME_FULLY_QUALIFIED ||
973- (defined ('T_NAME_QUALIFIED ' ) && $ tokens [$ startIndex ]['code ' ] === T_NAME_QUALIFIED )
974- ) {
950+ if ($ tokens [$ startIndex ]['code ' ] === T_NAME_FULLY_QUALIFIED ) {
975951 $ extractedUseStatement = ltrim ($ tokens [$ startIndex ]['content ' ], '\\' );
976952 if (!str_contains ($ extractedUseStatement , '\\' )) {
977953 return ; // Not a namespaced class
@@ -1031,7 +1007,7 @@ protected function checkPropertyForInstanceOf(File $phpcsFile, int $stackPtr): v
10311007 $ phpcsFile ->fixer ->replaceToken ($ lastIndex , $ addedUseStatement ['alias ' ]);
10321008 }
10331009 } else {
1034- // PHP CodeSniffer v4: replace single T_NAME_FULLY_QUALIFIED or T_NAME_QUALIFIED token
1010+ // PHP CodeSniffer v4: replace single T_NAME_FULLY_QUALIFIED token
10351011 if ($ addedUseStatement ['alias ' ] !== null ) {
10361012 $ phpcsFile ->fixer ->replaceToken ($ startIndex , $ addedUseStatement ['alias ' ]);
10371013 } else {
@@ -1365,13 +1341,9 @@ protected function parse(File $phpcsFile, int $startIndex, int $endIndex): array
13651341 break ;
13661342 }
13671343
1368- // PHP 8+: Check for T_NAME_FULLY_QUALIFIED or T_NAME_QUALIFIED token
1369- if (
1370- defined ('T_NAME_FULLY_QUALIFIED ' ) && (
1371- $ tokens [$ i ]['code ' ] === T_NAME_FULLY_QUALIFIED ||
1372- $ tokens [$ i ]['code ' ] === T_NAME_QUALIFIED
1373- )
1374- ) {
1344+ // PHP 8+: Check for T_NAME_FULLY_QUALIFIED token
1345+ // Note: T_NAME_QUALIFIED (partial names) are not auto-fixed as we can't determine the full namespace
1346+ if (defined ('T_NAME_FULLY_QUALIFIED ' ) && $ tokens [$ i ]['code ' ] === T_NAME_FULLY_QUALIFIED ) {
13751347 $ implements [] = [
13761348 'start ' => $ i ,
13771349 'end ' => $ i ,
0 commit comments