@@ -566,6 +566,16 @@ 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
+ $ nextNonEmptyToken = $ i ;
575
+ break ;
576
+ }
577
+ }
578
+
569
579
/*
570
580
If we are using \r\n newline characters, the \r and \n are sometimes
571
581
split over two tokens. This normally occurs after comments. We need
@@ -602,14 +612,17 @@ protected function tokenize($string)
602
612
}
603
613
604
614
/*
605
- Tokenize context sensitive keyword as string when it should be string.
615
+ Tokenize context- sensitive keyword as string when it should be string.
606
616
*/
607
617
608
618
if ($ tokenIsArray === true
609
619
&& isset (Util \Tokens::$ contextSensitiveKeywords [$ token [0 ]]) === true
610
620
&& (isset ($ this ->tstringContexts [$ finalTokens [$ lastNotEmptyToken ]['code ' ]]) === true
611
- || $ finalTokens [$ lastNotEmptyToken ]['content ' ] === '& ' )
621
+ || $ finalTokens [$ lastNotEmptyToken ]['content ' ] === '& '
622
+ || (isset ($ nextNonEmptyToken ) === true && $ tokens [$ nextNonEmptyToken ] === '( ' ))
612
623
) {
624
+ $ preserveKeyword = true ;
625
+
613
626
if (isset ($ this ->tstringContexts [$ finalTokens [$ lastNotEmptyToken ]['code ' ]]) === true ) {
614
627
$ preserveKeyword = false ;
615
628
@@ -649,8 +662,6 @@ protected function tokenize($string)
649
662
}//end if
650
663
651
664
if ($ finalTokens [$ lastNotEmptyToken ]['content ' ] === '& ' ) {
652
- $ preserveKeyword = true ;
653
-
654
665
for ($ i = ($ lastNotEmptyToken - 1 ); $ i >= 0 ; $ i --) {
655
666
if (isset (Util \Tokens::$ emptyTokens [$ finalTokens [$ i ]['code ' ]]) === true ) {
656
667
continue ;
@@ -664,6 +675,13 @@ protected function tokenize($string)
664
675
}
665
676
}
666
677
678
+ if (isset ($ nextNonEmptyToken ) === true
679
+ && $ tokens [$ nextNonEmptyToken ] === '( '
680
+ && $ token [0 ] === T_READONLY
681
+ ) {
682
+ $ preserveKeyword = false ;
683
+ }
684
+
667
685
if ($ preserveKeyword === false ) {
668
686
if (PHP_CODESNIFFER_VERBOSITY > 1 ) {
669
687
$ type = Util \Tokens::tokenName ($ token [0 ]);
@@ -1012,18 +1030,9 @@ protected function tokenize($string)
1012
1030
&& $ token [0 ] === T_STRING
1013
1031
&& strtolower ($ token [1 ]) === 'enum '
1014
1032
) {
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
1033
+ if (isset ($ tokens [$ nextNonEmptyToken ]) === true
1034
+ && is_array ($ tokens [$ nextNonEmptyToken ]) === true
1035
+ && $ tokens [$ nextNonEmptyToken ][0 ] === T_STRING
1027
1036
) {
1028
1037
// Modify $tokens directly so we can use it later when converting enum "case".
1029
1038
$ tokens [$ stackPtr ][0 ] = T_ENUM ;
@@ -1230,18 +1239,9 @@ protected function tokenize($string)
1230
1239
&& ($ token [0 ] === T_STRING
1231
1240
|| preg_match ('`^[a-zA-Z_\x80-\xff]` ' , $ token [1 ]) === 1 )
1232
1241
) {
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 ] === ': '
1242
+ if (isset ($ tokens [$ nextNonEmptyToken ]) === true
1243
+ && is_array ($ tokens [$ nextNonEmptyToken ]) === false
1244
+ && $ tokens [$ nextNonEmptyToken ] === ': '
1245
1245
) {
1246
1246
// Get the previous non-empty token.
1247
1247
for ($ j = ($ stackPtr - 1 ); $ j > 0 ; $ j --) {
0 commit comments