Mercurial > hg > isophonics-drupal-site
comparison vendor/squizlabs/php_codesniffer/CodeSniffer/Tokenizers/PHP.php @ 12:7a779792577d
Update Drupal core to v8.4.5 (via Composer)
author | Chris Cannam |
---|---|
date | Fri, 23 Feb 2018 15:52:07 +0000 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
11:bfffd8d7479a | 12:7a779792577d |
---|---|
720 | 720 |
721 if ($tokenIsArray === false && $token[0] === '?') { | 721 if ($tokenIsArray === false && $token[0] === '?') { |
722 $newToken = array(); | 722 $newToken = array(); |
723 $newToken['content'] = '?'; | 723 $newToken['content'] = '?'; |
724 | 724 |
725 $prevNonEmpty = null; | |
725 for ($i = ($stackPtr - 1); $i >= 0; $i--) { | 726 for ($i = ($stackPtr - 1); $i >= 0; $i--) { |
726 if (is_array($tokens[$i]) === true) { | 727 if (is_array($tokens[$i]) === true) { |
727 $tokenType = $tokens[$i][0]; | 728 $tokenType = $tokens[$i][0]; |
728 } else { | 729 } else { |
729 $tokenType = $tokens[$i]; | 730 $tokenType = $tokens[$i]; |
730 } | 731 } |
731 | 732 |
733 if ($prevNonEmpty === null | |
734 && isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokenType]) === false | |
735 ) { | |
736 // Found the previous non-empty token. | |
737 if ($tokenType === ':' || $tokenType === ',') { | |
738 $newToken['code'] = T_NULLABLE; | |
739 $newToken['type'] = 'T_NULLABLE'; | |
740 break; | |
741 } | |
742 | |
743 $prevNonEmpty = $tokenType; | |
744 } | |
745 | |
732 if ($tokenType === T_FUNCTION) { | 746 if ($tokenType === T_FUNCTION) { |
733 $newToken['code'] = T_NULLABLE; | 747 $newToken['code'] = T_NULLABLE; |
734 $newToken['type'] = 'T_NULLABLE'; | 748 $newToken['type'] = 'T_NULLABLE'; |
735 break; | 749 break; |
736 } else if (in_array($tokenType, array(T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO, '{', ';')) === true) { | 750 } else if (in_array($tokenType, array(T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO, '=', '{', ';')) === true) { |
737 $newToken['code'] = T_INLINE_THEN; | 751 $newToken['code'] = T_INLINE_THEN; |
738 $newToken['type'] = 'T_INLINE_THEN'; | 752 $newToken['type'] = 'T_INLINE_THEN'; |
739 | 753 |
740 $insideInlineIf[] = $stackPtr; | 754 $insideInlineIf[] = $stackPtr; |
741 break; | 755 break; |
742 } | 756 } |
743 } | 757 }//end for |
744 | 758 |
745 $finalTokens[$newStackPtr] = $newToken; | 759 $finalTokens[$newStackPtr] = $newToken; |
746 $newStackPtr++; | 760 $newStackPtr++; |
747 continue; | 761 continue; |
748 }//end if | 762 }//end if |
1275 | 1289 |
1276 // Unless there is a variable or a bracket before this token, | 1290 // Unless there is a variable or a bracket before this token, |
1277 // it is the start of an array being defined using the short syntax. | 1291 // it is the start of an array being defined using the short syntax. |
1278 $isShortArray = false; | 1292 $isShortArray = false; |
1279 $allowed = array( | 1293 $allowed = array( |
1280 T_CLOSE_SQUARE_BRACKET => T_CLOSE_SQUARE_BRACKET, | 1294 T_CLOSE_SQUARE_BRACKET => T_CLOSE_SQUARE_BRACKET, |
1281 T_CLOSE_PARENTHESIS => T_CLOSE_PARENTHESIS, | 1295 T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, |
1282 T_VARIABLE => T_VARIABLE, | 1296 T_CLOSE_PARENTHESIS => T_CLOSE_PARENTHESIS, |
1283 T_OBJECT_OPERATOR => T_OBJECT_OPERATOR, | 1297 T_VARIABLE => T_VARIABLE, |
1284 T_STRING => T_STRING, | 1298 T_OBJECT_OPERATOR => T_OBJECT_OPERATOR, |
1299 T_STRING => T_STRING, | |
1300 T_CONSTANT_ENCAPSED_STRING => T_CONSTANT_ENCAPSED_STRING, | |
1285 ); | 1301 ); |
1286 | 1302 |
1287 for ($x = ($i - 1); $x > 0; $x--) { | 1303 for ($x = ($i - 1); $x > 0; $x--) { |
1288 // If we hit a scope opener, the statement has ended | 1304 // If we hit a scope opener, the statement has ended |
1289 // without finding anything, so it's probably an array | 1305 // without finding anything, so it's probably an array |
1291 if (isset($tokens[$x]['scope_opener']) === true) { | 1307 if (isset($tokens[$x]['scope_opener']) === true) { |
1292 $isShortArray = true; | 1308 $isShortArray = true; |
1293 break; | 1309 break; |
1294 } | 1310 } |
1295 | 1311 |
1296 if (isset($tokens[$x]['bracket_opener']) === true | |
1297 && $x > $tokens[$x]['bracket_opener'] | |
1298 ) { | |
1299 $x = $tokens[$x]['bracket_opener']; | |
1300 continue; | |
1301 } | |
1302 | |
1303 if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$x]['code']]) === false) { | 1312 if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$x]['code']]) === false) { |
1304 if (isset($allowed[$tokens[$x]['code']]) === false) { | 1313 if (isset($allowed[$tokens[$x]['code']]) === false) { |
1305 $isShortArray = true; | 1314 $isShortArray = true; |
1306 } | 1315 } |
1307 | 1316 |
1308 break; | 1317 break; |
1309 } | 1318 } |
1310 }//end for | 1319 } |
1311 | 1320 |
1312 if ($isShortArray === true) { | 1321 if ($isShortArray === true) { |
1313 $tokens[$i]['code'] = T_OPEN_SHORT_ARRAY; | 1322 $tokens[$i]['code'] = T_OPEN_SHORT_ARRAY; |
1314 $tokens[$i]['type'] = 'T_OPEN_SHORT_ARRAY'; | 1323 $tokens[$i]['type'] = 'T_OPEN_SHORT_ARRAY'; |
1315 | 1324 |