@@ -12,7 +12,7 @@ class Helpers {
12
12
/**
13
13
* return int[]
14
14
*/
15
- public static function getEmptyTokens () {
15
+ public static function getPossibleEndOfFileTokens () {
16
16
return array_merge (
17
17
array_values (Tokens::$ emptyTokens ),
18
18
[
@@ -178,7 +178,7 @@ public static function getFunctionIndexForFunctionArgument(File $phpcsFile, $sta
178
178
return null ;
179
179
}
180
180
181
- $ nonFunctionTokenTypes = self :: getEmptyTokens () ;
181
+ $ nonFunctionTokenTypes = Tokens:: $ emptyTokens ;
182
182
$ nonFunctionTokenTypes [] = T_STRING ;
183
183
$ nonFunctionTokenTypes [] = T_BITWISE_AND ;
184
184
$ functionPtr = self ::getIntOrNull ($ phpcsFile ->findPrevious ($ nonFunctionTokenTypes , $ startOfArguments - 1 , null , true , null , true ));
@@ -218,7 +218,7 @@ public static function isTokenInsideFunctionUseImport(File $phpcsFile, $stackPtr
218
218
public static function getUseIndexForUseImport (File $ phpcsFile , $ stackPtr ) {
219
219
$ tokens = $ phpcsFile ->getTokens ();
220
220
221
- $ nonUseTokenTypes = self :: getEmptyTokens () ;
221
+ $ nonUseTokenTypes = Tokens:: $ emptyTokens ;
222
222
$ nonUseTokenTypes [] = T_VARIABLE ;
223
223
$ nonUseTokenTypes [] = T_ELLIPSIS ;
224
224
$ nonUseTokenTypes [] = T_COMMA ;
@@ -247,7 +247,7 @@ public static function findFunctionCall(File $phpcsFile, $stackPtr) {
247
247
$ openPtr = Helpers::findContainingOpeningBracket ($ phpcsFile , $ stackPtr );
248
248
if (is_int ($ openPtr )) {
249
249
// First non-whitespace thing and see if it's a T_STRING function name
250
- $ functionPtr = $ phpcsFile ->findPrevious (self :: getEmptyTokens () , $ openPtr - 1 , null , true , null , true );
250
+ $ functionPtr = $ phpcsFile ->findPrevious (Tokens:: $ emptyTokens , $ openPtr - 1 , null , true , null , true );
251
251
if (is_int ($ functionPtr ) && $ tokens [$ functionPtr ]['code ' ] === T_STRING ) {
252
252
return $ functionPtr ;
253
253
}
@@ -274,7 +274,7 @@ public static function findFunctionCallArguments(File $phpcsFile, $stackPtr) {
274
274
}
275
275
276
276
// $stackPtr is the function name, find our brackets after it
277
- $ openPtr = $ phpcsFile ->findNext (self :: getEmptyTokens () , $ stackPtr + 1 , null , true , null , true );
277
+ $ openPtr = $ phpcsFile ->findNext (Tokens:: $ emptyTokens , $ stackPtr + 1 , null , true , null , true );
278
278
if (($ openPtr === false ) || ($ tokens [$ openPtr ]['code ' ] !== T_OPEN_PARENTHESIS )) {
279
279
return [];
280
280
}
@@ -312,7 +312,7 @@ public static function getNextAssignPointer(File $phpcsFile, $stackPtr) {
312
312
$ tokens = $ phpcsFile ->getTokens ();
313
313
314
314
// Is the next non-whitespace an assignment?
315
- $ nextPtr = $ phpcsFile ->findNext (self :: getEmptyTokens () , $ stackPtr + 1 , null , true , null , true );
315
+ $ nextPtr = $ phpcsFile ->findNext (Tokens:: $ emptyTokens , $ stackPtr + 1 , null , true , null , true );
316
316
if (is_int ($ nextPtr )
317
317
&& isset (Tokens::$ assignmentTokens [$ tokens [$ nextPtr ]['code ' ]])
318
318
// Ignore double arrow to prevent triggering on `foreach ( $array as $k => $v )`.
@@ -540,14 +540,14 @@ public static function isArrowFunction(File $phpcsFile, $stackPtr) {
540
540
return false ;
541
541
}
542
542
// Make sure next non-space token is an open parenthesis
543
- $ openParenIndex = $ phpcsFile ->findNext (self :: getEmptyTokens () , $ stackPtr + 1 , null , true );
543
+ $ openParenIndex = $ phpcsFile ->findNext (Tokens:: $ emptyTokens , $ stackPtr + 1 , null , true );
544
544
if (! is_int ($ openParenIndex ) || $ tokens [$ openParenIndex ]['code ' ] !== T_OPEN_PARENTHESIS ) {
545
545
return false ;
546
546
}
547
547
// Find the associated close parenthesis
548
548
$ closeParenIndex = $ tokens [$ openParenIndex ]['parenthesis_closer ' ];
549
549
// Make sure the next token is a fat arrow
550
- $ fatArrowIndex = $ phpcsFile ->findNext (self :: getEmptyTokens () , $ closeParenIndex + 1 , null , true );
550
+ $ fatArrowIndex = $ phpcsFile ->findNext (Tokens:: $ emptyTokens , $ closeParenIndex + 1 , null , true );
551
551
if (! is_int ($ fatArrowIndex )) {
552
552
return false ;
553
553
}
@@ -575,14 +575,14 @@ public static function getArrowFunctionOpenClose(File $phpcsFile, $stackPtr) {
575
575
return null ;
576
576
}
577
577
// Make sure next non-space token is an open parenthesis
578
- $ openParenIndex = $ phpcsFile ->findNext (self :: getEmptyTokens () , $ stackPtr + 1 , null , true );
578
+ $ openParenIndex = $ phpcsFile ->findNext (Tokens:: $ emptyTokens , $ stackPtr + 1 , null , true );
579
579
if (! is_int ($ openParenIndex ) || $ tokens [$ openParenIndex ]['code ' ] !== T_OPEN_PARENTHESIS ) {
580
580
return null ;
581
581
}
582
582
// Find the associated close parenthesis
583
583
$ closeParenIndex = $ tokens [$ openParenIndex ]['parenthesis_closer ' ];
584
584
// Make sure the next token is a fat arrow
585
- $ fatArrowIndex = $ phpcsFile ->findNext (self :: getEmptyTokens () , $ closeParenIndex + 1 , null , true );
585
+ $ fatArrowIndex = $ phpcsFile ->findNext (Tokens:: $ emptyTokens , $ closeParenIndex + 1 , null , true );
586
586
if (! is_int ($ fatArrowIndex )) {
587
587
return null ;
588
588
}
@@ -632,7 +632,7 @@ public static function getListAssignments(File $phpcsFile, $listOpenerIndex) {
632
632
}
633
633
634
634
// Find the assignment (equals sign) which, if this is a list assignment, should be the next non-space token
635
- $ assignPtr = $ phpcsFile ->findNext (self :: getEmptyTokens () , $ closePtr + 1 , null , true );
635
+ $ assignPtr = $ phpcsFile ->findNext (Tokens:: $ emptyTokens , $ closePtr + 1 , null , true );
636
636
637
637
// If the next token isn't an assignment, check for nested brackets because we might be a nested assignment
638
638
if (! is_int ($ assignPtr ) || $ tokens [$ assignPtr ]['code ' ] !== T_EQUAL ) {
@@ -747,8 +747,10 @@ public static function isVariableANumericVariable($varName) {
747
747
*/
748
748
public static function isVariableInsideElseCondition (File $ phpcsFile , $ stackPtr ) {
749
749
$ tokens = $ phpcsFile ->getTokens ();
750
- $ nonFunctionTokenTypes = self :: getEmptyTokens () ;
750
+ $ nonFunctionTokenTypes = Tokens:: $ emptyTokens ;
751
751
$ nonFunctionTokenTypes [] = T_OPEN_PARENTHESIS ;
752
+ $ nonFunctionTokenTypes [] = T_INLINE_HTML ;
753
+ $ nonFunctionTokenTypes [] = T_CLOSE_TAG ;
752
754
$ nonFunctionTokenTypes [] = T_VARIABLE ;
753
755
$ nonFunctionTokenTypes [] = T_ELLIPSIS ;
754
756
$ nonFunctionTokenTypes [] = T_COMMA ;
@@ -869,7 +871,7 @@ public static function getScopeCloseForScopeOpen(File $phpcsFile, $scopeStartInd
869
871
public static function getLastNonEmptyTokenIndexInFile (File $ phpcsFile ) {
870
872
$ tokens = $ phpcsFile ->getTokens ();
871
873
foreach (array_reverse ($ tokens , true ) as $ index => $ token ) {
872
- if (! in_array ($ token ['code ' ], self ::getEmptyTokens (), true )) {
874
+ if (! in_array ($ token ['code ' ], self ::getPossibleEndOfFileTokens (), true )) {
873
875
return $ index ;
874
876
}
875
877
}
@@ -953,7 +955,7 @@ public static function getFunctionIndexForFunctionCallArgument(File $phpcsFile,
953
955
return null ;
954
956
}
955
957
956
- $ nonFunctionTokenTypes = self :: getEmptyTokens () ;
958
+ $ nonFunctionTokenTypes = Tokens:: $ emptyTokens ;
957
959
$ functionPtr = self ::getIntOrNull ($ phpcsFile ->findPrevious ($ nonFunctionTokenTypes , $ startOfArguments - 1 , null , true , null , true ));
958
960
if (! is_int ($ functionPtr ) || ! isset ($ tokens [$ functionPtr ]['code ' ])) {
959
961
return null ;
@@ -997,7 +999,7 @@ public static function isVariableInsideIssetOrEmpty(File $phpcsFile, $stackPtr)
997
999
*/
998
1000
public static function isVariableArrayPushShortcut (File $ phpcsFile , $ stackPtr ) {
999
1001
$ tokens = $ phpcsFile ->getTokens ();
1000
- $ nonFunctionTokenTypes = self :: getEmptyTokens () ;
1002
+ $ nonFunctionTokenTypes = Tokens:: $ emptyTokens ;
1001
1003
1002
1004
$ arrayPushOperatorIndex1 = self ::getIntOrNull ($ phpcsFile ->findNext ($ nonFunctionTokenTypes , $ stackPtr + 1 , null , true , null , true ));
1003
1005
if (! is_int ($ arrayPushOperatorIndex1 )) {
@@ -1095,7 +1097,7 @@ public static function isTokenInsideAssignmentLHS(File $phpcsFile, $stackPtr) {
1095
1097
public static function isTokenVariableVariable (File $ phpcsFile , $ stackPtr ) {
1096
1098
$ tokens = $ phpcsFile ->getTokens ();
1097
1099
1098
- $ prev = $ phpcsFile ->findPrevious (self :: getEmptyTokens () , ($ stackPtr - 1 ), null , true );
1100
+ $ prev = $ phpcsFile ->findPrevious (Tokens:: $ emptyTokens , ($ stackPtr - 1 ), null , true );
1099
1101
if ($ prev === false ) {
1100
1102
return false ;
1101
1103
}
@@ -1106,7 +1108,7 @@ public static function isTokenVariableVariable(File $phpcsFile, $stackPtr) {
1106
1108
return false ;
1107
1109
}
1108
1110
1109
- $ prevPrev = $ phpcsFile ->findPrevious (self :: getEmptyTokens () , ($ prev - 1 ), null , true );
1111
+ $ prevPrev = $ phpcsFile ->findPrevious (Tokens:: $ emptyTokens , ($ prev - 1 ), null , true );
1110
1112
if ($ prevPrev !== false && $ tokens [$ prevPrev ]['code ' ] === T_DOLLAR ) {
1111
1113
return true ;
1112
1114
}
0 commit comments