@@ -19,7 +19,7 @@ class Helpers
1919 public static function getPossibleEndOfFileTokens ()
2020 {
2121 return array_merge (
22- array_values (Tokens:: $ emptyTokens ),
22+ array_values (self :: getEmptyTokens () ),
2323 [
2424 T_INLINE_HTML ,
2525 T_CLOSE_TAG ,
@@ -242,7 +242,7 @@ public static function getFunctionIndexForFunctionParameter(File $phpcsFile, $st
242242 return null ;
243243 }
244244
245- $ nonFunctionTokenTypes = Tokens:: $ emptyTokens ;
245+ $ nonFunctionTokenTypes = self :: getEmptyTokens () ;
246246 $ nonFunctionTokenTypes [] = T_STRING ;
247247 $ nonFunctionTokenTypes [] = T_BITWISE_AND ;
248248 $ functionPtr = self ::getIntOrNull ($ phpcsFile ->findPrevious ($ nonFunctionTokenTypes , $ startOfArguments - 1 , null , true , null , true ));
@@ -284,7 +284,7 @@ public static function getUseIndexForUseImport(File $phpcsFile, $stackPtr)
284284 {
285285 $ tokens = $ phpcsFile ->getTokens ();
286286
287- $ nonUseTokenTypes = Tokens:: $ emptyTokens ;
287+ $ nonUseTokenTypes = self :: getEmptyTokens () ;
288288 $ nonUseTokenTypes [] = T_VARIABLE ;
289289 $ nonUseTokenTypes [] = T_ELLIPSIS ;
290290 $ nonUseTokenTypes [] = T_COMMA ;
@@ -318,7 +318,7 @@ public static function findFunctionCall(File $phpcsFile, $stackPtr)
318318 $ openPtr = self ::findContainingOpeningBracket ($ phpcsFile , $ stackPtr );
319319 if (is_int ($ openPtr )) {
320320 // First non-whitespace thing and see if it's a T_STRING function name
321- $ functionPtr = $ phpcsFile ->findPrevious (Tokens:: $ emptyTokens , $ openPtr - 1 , null , true , null , true );
321+ $ functionPtr = $ phpcsFile ->findPrevious (self :: getEmptyTokens () , $ openPtr - 1 , null , true , null , true );
322322 if (is_int ($ functionPtr ) && $ tokens [$ functionPtr ]['code ' ] === T_STRING ) {
323323 return $ functionPtr ;
324324 }
@@ -346,7 +346,7 @@ public static function findFunctionCallArguments(File $phpcsFile, $stackPtr)
346346 }
347347
348348 // $stackPtr is the function name, find our brackets after it
349- $ openPtr = $ phpcsFile ->findNext (Tokens:: $ emptyTokens , $ stackPtr + 1 , null , true , null , true );
349+ $ openPtr = $ phpcsFile ->findNext (self :: getEmptyTokens () , $ stackPtr + 1 , null , true , null , true );
350350 if (($ openPtr === false ) || ($ tokens [$ openPtr ]['code ' ] !== T_OPEN_PARENTHESIS )) {
351351 return [];
352352 }
@@ -382,6 +382,21 @@ public static function findFunctionCallArguments(File $phpcsFile, $stackPtr)
382382 return $ argPtrs ;
383383 }
384384
385+ /**
386+ * Compatibility handler for phpcs 3.x/4.x
387+ * @return array
388+ */
389+ public static function getEmptyTokens ()
390+ {
391+ if (defined ('Tokens::EMPTY_TOKENS ' )) {
392+ return Tokens::EMPTY_TOKENS ;
393+ }
394+ if (isset (Tokens::$ emptyTokens )) {
395+ return Tokens::$ emptyTokens ;
396+ }
397+ return [];
398+ }
399+
385400 /**
386401 * Compatibility handler for phpcs 3.x/4.x
387402 * @return array
@@ -442,7 +457,7 @@ public static function getNextAssignPointer(File $phpcsFile, $stackPtr)
442457 $ tokens = $ phpcsFile ->getTokens ();
443458
444459 // Is the next non-whitespace an assignment?
445- $ nextPtr = $ phpcsFile ->findNext (Tokens:: $ emptyTokens , $ stackPtr + 1 , null , true , null , true );
460+ $ nextPtr = $ phpcsFile ->findNext (self :: getEmptyTokens () , $ stackPtr + 1 , null , true , null , true );
446461 if (is_int ($ nextPtr )
447462 && self ::hasAssignmentToken ($ tokens , $ nextPtr )
448463 // Ignore double arrow to prevent triggering on `foreach ( $array as $k => $v )`.
@@ -515,7 +530,8 @@ public static function getVariablesInsideCompact(File $phpcsFile, $stackPtr, $ar
515530
516531 foreach ($ arguments as $ argumentPtrs ) {
517532 $ argumentPtrs = array_values (array_filter ($ argumentPtrs , function ($ argumentPtr ) use ($ tokens ) {
518- return isset (Tokens::$ emptyTokens [$ tokens [$ argumentPtr ]['code ' ]]) === false ;
533+ $ emptyTokens = self ::getEmptyTokens ();
534+ return isset ($ emptyTokens [$ tokens [$ argumentPtr ]['code ' ]]) === false ;
519535 }));
520536 if (empty ($ argumentPtrs )) {
521537 continue ;
@@ -762,14 +778,14 @@ public static function isArrowFunction(File $phpcsFile, $stackPtr)
762778 return false ;
763779 }
764780 // Make sure next non-space token is an open parenthesis
765- $ openParenIndex = $ phpcsFile ->findNext (Tokens:: $ emptyTokens , $ stackPtr + 1 , null , true );
781+ $ openParenIndex = $ phpcsFile ->findNext (self :: getEmptyTokens () , $ stackPtr + 1 , null , true );
766782 if (! is_int ($ openParenIndex ) || $ tokens [$ openParenIndex ]['code ' ] !== T_OPEN_PARENTHESIS ) {
767783 return false ;
768784 }
769785 // Find the associated close parenthesis
770786 $ closeParenIndex = $ tokens [$ openParenIndex ]['parenthesis_closer ' ];
771787 // Make sure the next token is a fat arrow
772- $ fatArrowIndex = $ phpcsFile ->findNext (Tokens:: $ emptyTokens , $ closeParenIndex + 1 , null , true );
788+ $ fatArrowIndex = $ phpcsFile ->findNext (self :: getEmptyTokens () , $ closeParenIndex + 1 , null , true );
773789 if (! is_int ($ fatArrowIndex )) {
774790 return false ;
775791 }
@@ -801,14 +817,14 @@ public static function getArrowFunctionOpenClose(File $phpcsFile, $stackPtr)
801817 return null ;
802818 }
803819 // Make sure next non-space token is an open parenthesis
804- $ openParenIndex = $ phpcsFile ->findNext (Tokens:: $ emptyTokens , $ stackPtr + 1 , null , true );
820+ $ openParenIndex = $ phpcsFile ->findNext (self :: getEmptyTokens () , $ stackPtr + 1 , null , true );
805821 if (! is_int ($ openParenIndex ) || $ tokens [$ openParenIndex ]['code ' ] !== T_OPEN_PARENTHESIS ) {
806822 return null ;
807823 }
808824 // Find the associated close parenthesis
809825 $ closeParenIndex = $ tokens [$ openParenIndex ]['parenthesis_closer ' ];
810826 // Make sure the next token is a fat arrow or a return type
811- $ fatArrowIndex = $ phpcsFile ->findNext (Tokens:: $ emptyTokens , $ closeParenIndex + 1 , null , true );
827+ $ fatArrowIndex = $ phpcsFile ->findNext (self :: getEmptyTokens () , $ closeParenIndex + 1 , null , true );
812828 if (! is_int ($ fatArrowIndex )) {
813829 return null ;
814830 }
@@ -930,7 +946,7 @@ private static function isListAssignment(File $phpcsFile, $listOpenerIndex)
930946 // If $listOpenerIndex is the open parenthesis of `list($a) = $b;`, then
931947 // match that too.
932948 if ($ tokens [$ listOpenerIndex ]['code ' ] === T_OPEN_PARENTHESIS ) {
933- $ previousTokenPtr = $ phpcsFile ->findPrevious (Tokens:: $ emptyTokens , $ listOpenerIndex - 1 , null , true );
949+ $ previousTokenPtr = $ phpcsFile ->findPrevious (self :: getEmptyTokens () , $ listOpenerIndex - 1 , null , true );
934950 if (
935951 isset ($ tokens [$ previousTokenPtr ])
936952 && $ tokens [$ previousTokenPtr ]['code ' ] === T_LIST
@@ -946,7 +962,7 @@ private static function isListAssignment(File $phpcsFile, $listOpenerIndex)
946962 //
947963 // Match `if (true) [$a] = $b;`
948964 if ($ tokens [$ listOpenerIndex ]['code ' ] === T_OPEN_SQUARE_BRACKET ) {
949- $ previousTokenPtr = $ phpcsFile ->findPrevious (Tokens:: $ emptyTokens , $ listOpenerIndex - 1 , null , true );
965+ $ previousTokenPtr = $ phpcsFile ->findPrevious (self :: getEmptyTokens () , $ listOpenerIndex - 1 , null , true );
950966 if (
951967 isset ($ tokens [$ previousTokenPtr ])
952968 && $ tokens [$ previousTokenPtr ]['code ' ] === T_CLOSE_PARENTHESIS
@@ -991,7 +1007,7 @@ public static function getListAssignments(File $phpcsFile, $listOpenerIndex)
9911007 }
9921008
9931009 // Find the assignment (equals sign) which, if this is a list assignment, should be the next non-space token
994- $ assignPtr = $ phpcsFile ->findNext (Tokens:: $ emptyTokens , $ closePtr + 1 , null , true );
1010+ $ assignPtr = $ phpcsFile ->findNext (self :: getEmptyTokens () , $ closePtr + 1 , null , true );
9951011
9961012 // If the next token isn't an assignment, check for nested brackets because we might be a nested assignment
9971013 if (! is_int ($ assignPtr ) || $ tokens [$ assignPtr ]['code ' ] !== T_EQUAL ) {
@@ -1125,7 +1141,7 @@ public static function isVariableANumericVariable($varName)
11251141 public static function isVariableInsideElseCondition (File $ phpcsFile , $ stackPtr )
11261142 {
11271143 $ tokens = $ phpcsFile ->getTokens ();
1128- $ nonFunctionTokenTypes = Tokens:: $ emptyTokens ;
1144+ $ nonFunctionTokenTypes = self :: getEmptyTokens () ;
11291145 $ nonFunctionTokenTypes [] = T_OPEN_PARENTHESIS ;
11301146 $ nonFunctionTokenTypes [] = T_INLINE_HTML ;
11311147 $ nonFunctionTokenTypes [] = T_CLOSE_TAG ;
@@ -1347,7 +1363,7 @@ public static function getFunctionIndexForFunctionCallArgument(File $phpcsFile,
13471363 return null ;
13481364 }
13491365
1350- $ nonFunctionTokenTypes = Tokens:: $ emptyTokens ;
1366+ $ nonFunctionTokenTypes = self :: getEmptyTokens () ;
13511367 $ functionPtr = self ::getIntOrNull ($ phpcsFile ->findPrevious ($ nonFunctionTokenTypes , $ startOfArguments - 1 , null , true , null , true ));
13521368 if (! is_int ($ functionPtr ) || ! isset ($ tokens [$ functionPtr ]['code ' ])) {
13531369 return null ;
@@ -1416,7 +1432,7 @@ public static function isVariableInsideIssetOrEmpty(File $phpcsFile, $stackPtr)
14161432 public static function isVariableArrayPushShortcut (File $ phpcsFile , $ stackPtr )
14171433 {
14181434 $ tokens = $ phpcsFile ->getTokens ();
1419- $ nonFunctionTokenTypes = Tokens:: $ emptyTokens ;
1435+ $ nonFunctionTokenTypes = self :: getEmptyTokens () ;
14201436
14211437 $ arrayPushOperatorIndex1 = self ::getIntOrNull ($ phpcsFile ->findNext ($ nonFunctionTokenTypes , $ stackPtr + 1 , null , true , null , true ));
14221438 if (! is_int ($ arrayPushOperatorIndex1 )) {
@@ -1518,7 +1534,7 @@ public static function isTokenVariableVariable(File $phpcsFile, $stackPtr)
15181534 {
15191535 $ tokens = $ phpcsFile ->getTokens ();
15201536
1521- $ prev = $ phpcsFile ->findPrevious (Tokens:: $ emptyTokens , ($ stackPtr - 1 ), null , true );
1537+ $ prev = $ phpcsFile ->findPrevious (self :: getEmptyTokens () , ($ stackPtr - 1 ), null , true );
15221538 if ($ prev === false ) {
15231539 return false ;
15241540 }
@@ -1529,7 +1545,7 @@ public static function isTokenVariableVariable(File $phpcsFile, $stackPtr)
15291545 return false ;
15301546 }
15311547
1532- $ prevPrev = $ phpcsFile ->findPrevious (Tokens:: $ emptyTokens , ($ prev - 1 ), null , true );
1548+ $ prevPrev = $ phpcsFile ->findPrevious (self :: getEmptyTokens () , ($ prev - 1 ), null , true );
15331549 if ($ prevPrev !== false && $ tokens [$ prevPrev ]['code ' ] === T_DOLLAR ) {
15341550 return true ;
15351551 }
@@ -1693,7 +1709,7 @@ public static function isConstructorPromotion(File $phpcsFile, $stackPtr)
16931709 if (in_array ($ tokens [$ i ]['code ' ], self ::getScopeModifiers (), true )) {
16941710 return true ;
16951711 }
1696- if (in_array ($ tokens [$ i ]['code ' ], Tokens:: $ emptyTokens , true )) {
1712+ if (in_array ($ tokens [$ i ]['code ' ], self :: getEmptyTokens () , true )) {
16971713 continue ;
16981714 }
16991715 if ($ tokens [$ i ]['content ' ] === 'readonly ' ) {
@@ -1775,7 +1791,7 @@ private static function isTokenPossiblyPartOfTypehint(File $phpcsFile, $stackPtr
17751791 if ($ token ['content ' ] === '| ' ) {
17761792 return true ;
17771793 }
1778- if (in_array ($ token ['code ' ], Tokens:: $ emptyTokens )) {
1794+ if (in_array ($ token ['code ' ], self :: getEmptyTokens () )) {
17791795 return true ;
17801796 }
17811797 return false ;
@@ -1847,7 +1863,7 @@ public static function isFunctionBodyEmpty(File $phpcsFile, $stackPtr)
18471863 $ functionScopeStart = $ tokens [$ stackPtr ]['scope_opener ' ];
18481864 $ functionScopeEnd = $ tokens [$ stackPtr ]['scope_closer ' ];
18491865 $ tokensToIgnore = array_merge (
1850- Tokens:: $ emptyTokens ,
1866+ self :: getEmptyTokens () ,
18511867 [
18521868 T_RETURN ,
18531869 T_SEMICOLON ,
0 commit comments