File tree Expand file tree Collapse file tree 7 files changed +43
-10
lines changed
Standards/Squiz/Tests/Arrays Expand file tree Collapse file tree 7 files changed +43
-10
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
3838 - Fixed bug #2850 : Generic.PHP.LowerCaseKeyword complains __HALT_COMPILER is uppercase
3939 - Fixed bug #2853 : Undefined variable error when using Info report
4040 -- Thanks to Juliette Reinders Folmer for the patch
41+ - Fixed bug #2865 : Double arrow tokenized as T_STRING when placed after function named "fn"
4142 - Fixed bug #2868 : phpcs:ignore annotation doesnt work inside a docblock
4243 - Fixed bug #2878 : PSR12.Files.FileHeader conflicts with Generic.Files.LineEndings
4344 </notes>
Original file line number Diff line number Diff line change @@ -424,6 +424,11 @@ $array = array(
424424 3 => '3 ' ,
425425 );
426426
427+ $ foo = array (
428+ $ this ->fn => 'value ' ,
429+ $ foo ->fn => 'value ' ,
430+ );
431+
427432// Intentional syntax error.
428433$ a = array (
429434 'a ' =>
Original file line number Diff line number Diff line change @@ -452,6 +452,11 @@ $array = array(
452452 3 => '3',
453453 );
454454
455+ $foo = array(
456+ $this->fn => 'value',
457+ $foo->fn => 'value',
458+ );
459+
455460// Intentional syntax error.
456461$a = array(
457462 'a' =>
Original file line number Diff line number Diff line change @@ -413,6 +413,11 @@ $array = [
413413 3 => '3 ' ,
414414 ];
415415
416+ $ foo = [
417+ $ this ->fn => 'value ' ,
418+ $ foo ->fn => 'value ' ,
419+ ];
420+
416421// Intentional syntax error.
417422$ a = [
418423 'a ' =>
Original file line number Diff line number Diff line change @@ -439,6 +439,11 @@ $array = [
439439 3 => '3',
440440 ];
441441
442+ $foo = [
443+ $this->fn => 'value',
444+ $foo->fn => 'value',
445+ ];
446+
442447// Intentional syntax error.
443448$a = [
444449 'a' =>
Original file line number Diff line number Diff line change @@ -113,6 +113,7 @@ public function getErrorList($testFile='')
113113 370 => 1 ,
114114 383 => 1 ,
115115 394 => 1 ,
116+ 429 => 1 ,
116117 ];
117118 case 'ArrayDeclarationUnitTest.2.inc ' :
118119 return [
@@ -188,6 +189,7 @@ public function getErrorList($testFile='')
188189 358 => 1 ,
189190 372 => 1 ,
190191 383 => 1 ,
192+ 418 => 1 ,
191193 ];
192194 default :
193195 return [];
Original file line number Diff line number Diff line change @@ -1227,6 +1227,9 @@ protected function tokenize($string)
12271227 // detect the T_FN token more easily.
12281228 $ tokens [$ stackPtr ][0 ] = T_FN ;
12291229 $ token [0 ] = T_FN ;
1230+ if (PHP_CODESNIFFER_VERBOSITY > 1 ) {
1231+ echo "\t\t* token $ stackPtr changed from T_STRING to T_FN " .PHP_EOL ;
1232+ }
12301233 }
12311234
12321235 /*
@@ -1241,18 +1244,25 @@ protected function tokenize($string)
12411244 || $ token [0 ] === T_FN )
12421245 && $ finalTokens [$ lastNotEmptyToken ]['code ' ] !== T_USE
12431246 ) {
1244- for ($ x = ($ stackPtr + 1 ); $ x < $ numTokens ; $ x ++) {
1245- if (is_array ($ tokens [$ x ]) === false
1246- || isset (Util \Tokens::$ emptyTokens [$ tokens [$ x ][0 ]]) === false
1247- ) {
1248- // Non-empty content.
1249- break ;
1247+ if ($ token [0 ] === T_FUNCTION ) {
1248+ for ($ x = ($ stackPtr + 1 ); $ x < $ numTokens ; $ x ++) {
1249+ if (is_array ($ tokens [$ x ]) === false
1250+ || isset (Util \Tokens::$ emptyTokens [$ tokens [$ x ][0 ]]) === false
1251+ ) {
1252+ // Non-empty content.
1253+ break ;
1254+ }
12501255 }
1251- }
12521256
1253- if ($ x < $ numTokens && is_array ($ tokens [$ x ]) === true ) {
1254- $ tokens [$ x ][0 ] = T_STRING ;
1255- }
1257+ if ($ x < $ numTokens && is_array ($ tokens [$ x ]) === true ) {
1258+ if (PHP_CODESNIFFER_VERBOSITY > 1 ) {
1259+ $ oldType = Util \Tokens::tokenName ($ tokens [$ x ][0 ]);
1260+ echo "\t\t* token $ x changed from $ oldType to T_STRING " .PHP_EOL ;
1261+ }
1262+
1263+ $ tokens [$ x ][0 ] = T_STRING ;
1264+ }
1265+ }//end if
12561266
12571267 /*
12581268 This is a special condition for T_ARRAY tokens used for
You can’t perform that action at this time.
0 commit comments