@@ -566,6 +566,17 @@ protected function tokenize($string)
566
566
$ lastNotEmptyToken = ($ newStackPtr - 1 );
567
567
}
568
568
569
+ // Get the next non-empty token.
570
+ $ nextNonEmptyToken = null ;
571
+ for ($ i = ($ stackPtr + 1 ); $ i < $ numTokens ; $ i ++) {
572
+ if (is_array ($ tokens [$ i ]) === false
573
+ || isset (Util \Tokens::$ emptyTokens [$ tokens [$ i ][0 ]]) === false
574
+ ) {
575
+ $ nextNonEmptyToken = $ i ;
576
+ break ;
577
+ }
578
+ }
579
+
569
580
/*
570
581
If we are using \r\n newline characters, the \r and \n are sometimes
571
582
split over two tokens. This normally occurs after comments. We need
@@ -602,14 +613,17 @@ protected function tokenize($string)
602
613
}
603
614
604
615
/*
605
- Tokenize context sensitive keyword as string when it should be string.
616
+ Tokenize context- sensitive keyword as string when it should be string.
606
617
*/
607
618
608
619
if ($ tokenIsArray === true
609
620
&& isset (Util \Tokens::$ contextSensitiveKeywords [$ token [0 ]]) === true
610
621
&& (isset ($ this ->tstringContexts [$ finalTokens [$ lastNotEmptyToken ]['code ' ]]) === true
611
- || $ finalTokens [$ lastNotEmptyToken ]['content ' ] === '& ' )
622
+ || $ finalTokens [$ lastNotEmptyToken ]['content ' ] === '& '
623
+ || (isset ($ nextNonEmptyToken ) === true && $ tokens [$ nextNonEmptyToken ] === '( ' ))
612
624
) {
625
+ $ preserveKeyword = true ;
626
+
613
627
if (isset ($ this ->tstringContexts [$ finalTokens [$ lastNotEmptyToken ]['code ' ]]) === true ) {
614
628
$ preserveKeyword = false ;
615
629
@@ -649,8 +663,6 @@ protected function tokenize($string)
649
663
}//end if
650
664
651
665
if ($ finalTokens [$ lastNotEmptyToken ]['content ' ] === '& ' ) {
652
- $ preserveKeyword = true ;
653
-
654
666
for ($ i = ($ lastNotEmptyToken - 1 ); $ i >= 0 ; $ i --) {
655
667
if (isset (Util \Tokens::$ emptyTokens [$ finalTokens [$ i ]['code ' ]]) === true ) {
656
668
continue ;
@@ -664,6 +676,13 @@ protected function tokenize($string)
664
676
}
665
677
}
666
678
679
+ if (isset ($ nextNonEmptyToken ) === true
680
+ && $ tokens [$ nextNonEmptyToken ] === '( '
681
+ && $ token [0 ] === T_READONLY
682
+ ) {
683
+ $ preserveKeyword = false ;
684
+ }
685
+
667
686
if ($ preserveKeyword === false ) {
668
687
if (PHP_CODESNIFFER_VERBOSITY > 1 ) {
669
688
$ type = Util \Tokens::tokenName ($ token [0 ]);
@@ -1012,18 +1031,9 @@ protected function tokenize($string)
1012
1031
&& $ token [0 ] === T_STRING
1013
1032
&& strtolower ($ token [1 ]) === 'enum '
1014
1033
) {
1015
- // Get the next non-empty token.
1016
- for ($ i = ($ stackPtr + 1 ); $ i < $ numTokens ; $ i ++) {
1017
- if (is_array ($ tokens [$ i ]) === false
1018
- || isset (Util \Tokens::$ emptyTokens [$ tokens [$ i ][0 ]]) === false
1019
- ) {
1020
- break ;
1021
- }
1022
- }
1023
-
1024
- if (isset ($ tokens [$ i ]) === true
1025
- && is_array ($ tokens [$ i ]) === true
1026
- && $ tokens [$ i ][0 ] === T_STRING
1034
+ if (isset ($ tokens [$ nextNonEmptyToken ]) === true
1035
+ && is_array ($ tokens [$ nextNonEmptyToken ]) === true
1036
+ && $ tokens [$ nextNonEmptyToken ][0 ] === T_STRING
1027
1037
) {
1028
1038
// Modify $tokens directly so we can use it later when converting enum "case".
1029
1039
$ tokens [$ stackPtr ][0 ] = T_ENUM ;
@@ -1230,18 +1240,9 @@ protected function tokenize($string)
1230
1240
&& ($ token [0 ] === T_STRING
1231
1241
|| preg_match ('`^[a-zA-Z_\x80-\xff]` ' , $ token [1 ]) === 1 )
1232
1242
) {
1233
- // Get the next non-empty token.
1234
- for ($ i = ($ stackPtr + 1 ); $ i < $ numTokens ; $ i ++) {
1235
- if (is_array ($ tokens [$ i ]) === false
1236
- || isset (Util \Tokens::$ emptyTokens [$ tokens [$ i ][0 ]]) === false
1237
- ) {
1238
- break ;
1239
- }
1240
- }
1241
-
1242
- if (isset ($ tokens [$ i ]) === true
1243
- && is_array ($ tokens [$ i ]) === false
1244
- && $ tokens [$ i ] === ': '
1243
+ if (isset ($ tokens [$ nextNonEmptyToken ]) === true
1244
+ && is_array ($ tokens [$ nextNonEmptyToken ]) === false
1245
+ && $ tokens [$ nextNonEmptyToken ] === ': '
1245
1246
) {
1246
1247
// Get the previous non-empty token.
1247
1248
for ($ j = ($ stackPtr - 1 ); $ j > 0 ; $ j --) {
@@ -1287,17 +1288,8 @@ protected function tokenize($string)
1287
1288
&& strtolower ($ token [1 ]) === 'readonly '
1288
1289
&& isset ($ this ->tstringContexts [$ finalTokens [$ lastNotEmptyToken ]['code ' ]]) === false
1289
1290
) {
1290
- // Get the next non-whitespace token.
1291
- for ($ i = ($ stackPtr + 1 ); $ i < $ numTokens ; $ i ++) {
1292
- if (is_array ($ tokens [$ i ]) === false
1293
- || $ tokens [$ i ][0 ] !== T_WHITESPACE
1294
- ) {
1295
- break ;
1296
- }
1297
- }
1298
-
1299
- if (isset ($ tokens [$ i ]) === false
1300
- || $ tokens [$ i ] !== '( '
1291
+ if (isset ($ tokens [$ nextNonEmptyToken ]) === false
1292
+ || $ tokens [$ nextNonEmptyToken ] !== '( '
1301
1293
) {
1302
1294
$ finalTokens [$ newStackPtr ] = [
1303
1295
'code ' => T_READONLY ,
0 commit comments