comparison vendor/squizlabs/php_codesniffer/src/Tokenizers/PHP.php @ 18:af1871eacc83

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:33:08 +0100
parents 129ea1e6d783
children
comparison
equal deleted inserted replaced
17:129ea1e6d783 18:af1871eacc83
264 264
265 /** 265 /**
266 * A list of tokens that end the scope. 266 * A list of tokens that end the scope.
267 * 267 *
268 * This array is just a unique collection of the end tokens 268 * This array is just a unique collection of the end tokens
269 * from the _scopeOpeners array. The data is duplicated here to 269 * from the scopeOpeners array. The data is duplicated here to
270 * save time during parsing of the file. 270 * save time during parsing of the file.
271 * 271 *
272 * @var array 272 * @var array
273 */ 273 */
274 public $endScopeTokens = [ 274 public $endScopeTokens = [
502 } 502 }
503 503
504 echo ": $type => $content"; 504 echo ": $type => $content";
505 }//end if 505 }//end if
506 506
507 if ($newStackPtr > 0 && $finalTokens[($newStackPtr - 1)]['code'] !== T_WHITESPACE) { 507 if ($newStackPtr > 0
508 && isset(Util\Tokens::$emptyTokens[$finalTokens[($newStackPtr - 1)]['code']]) === false
509 ) {
508 $lastNotEmptyToken = ($newStackPtr - 1); 510 $lastNotEmptyToken = ($newStackPtr - 1);
509 } 511 }
510 512
511 /* 513 /*
512 If we are using \r\n newline characters, the \r and \n are sometimes 514 If we are using \r\n newline characters, the \r and \n are sometimes
780 && $tokens[($stackPtr + 1)][0] === T_WHITESPACE 782 && $tokens[($stackPtr + 1)][0] === T_WHITESPACE
781 && $tokens[($stackPtr + 2)][0] === T_STRING 783 && $tokens[($stackPtr + 2)][0] === T_STRING
782 && strtolower($tokens[($stackPtr + 2)][1]) === 'from' 784 && strtolower($tokens[($stackPtr + 2)][1]) === 'from'
783 ) { 785 ) {
784 // Could be multi-line, so just the token stack. 786 // Could be multi-line, so just the token stack.
785 $token[0] = T_YIELD_FROM; 787 $token[0] = T_YIELD_FROM;
786 $token[1] = $token[1].$tokens[($stackPtr + 1)][1].$tokens[($stackPtr + 2)][1]; 788 $token[1] .= $tokens[($stackPtr + 1)][1].$tokens[($stackPtr + 2)][1];
787 789
788 if (PHP_CODESNIFFER_VERBOSITY > 1) { 790 if (PHP_CODESNIFFER_VERBOSITY > 1) {
789 for ($i = ($stackPtr + 1); $i <= ($stackPtr + 2); $i++) { 791 for ($i = ($stackPtr + 1); $i <= ($stackPtr + 2); $i++) {
790 $type = Util\Tokens::tokenName($tokens[$i][0]); 792 $type = Util\Tokens::tokenName($tokens[$i][0]);
791 $content = Util\Common::prepareForOutput($tokens[$i][1]); 793 $content = Util\Common::prepareForOutput($tokens[$i][1]);
814 && $tokens[($stackPtr + 1)][0] === T_WHITESPACE 816 && $tokens[($stackPtr + 1)][0] === T_WHITESPACE
815 && $tokens[($stackPtr + 2)][0] === T_STRING 817 && $tokens[($stackPtr + 2)][0] === T_STRING
816 && strtolower($tokens[($stackPtr + 2)][1]) === 'from' 818 && strtolower($tokens[($stackPtr + 2)][1]) === 'from'
817 ) { 819 ) {
818 // Could be multi-line, so just just the token stack. 820 // Could be multi-line, so just just the token stack.
819 $token[0] = T_YIELD_FROM; 821 $token[0] = T_YIELD_FROM;
820 $token[1] = $token[1].$tokens[($stackPtr + 1)][1].$tokens[($stackPtr + 2)][1]; 822 $token[1] .= $tokens[($stackPtr + 1)][1].$tokens[($stackPtr + 2)][1];
821 823
822 if (PHP_CODESNIFFER_VERBOSITY > 1) { 824 if (PHP_CODESNIFFER_VERBOSITY > 1) {
823 for ($i = ($stackPtr + 1); $i <= ($stackPtr + 2); $i++) { 825 for ($i = ($stackPtr + 1); $i <= ($stackPtr + 2); $i++) {
824 $type = Util\Tokens::tokenName($tokens[$i][0]); 826 $type = Util\Tokens::tokenName($tokens[$i][0]);
825 $content = Util\Common::prepareForOutput($tokens[$i][1]); 827 $content = Util\Common::prepareForOutput($tokens[$i][1]);
999 1001
1000 if ($tokenType === T_FUNCTION) { 1002 if ($tokenType === T_FUNCTION) {
1001 $newToken['code'] = T_NULLABLE; 1003 $newToken['code'] = T_NULLABLE;
1002 $newToken['type'] = 'T_NULLABLE'; 1004 $newToken['type'] = 'T_NULLABLE';
1003 break; 1005 break;
1004 } else if (in_array($tokenType, [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO, '=', '{', ';']) === true) { 1006 } else if (in_array($tokenType, [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO, '=', '{', ';'], true) === true) {
1005 $newToken['code'] = T_INLINE_THEN; 1007 $newToken['code'] = T_INLINE_THEN;
1006 $newToken['type'] = 'T_INLINE_THEN'; 1008 $newToken['type'] = 'T_INLINE_THEN';
1007 1009
1008 $insideInlineIf[] = $stackPtr; 1010 $insideInlineIf[] = $stackPtr;
1009 break; 1011 break;
1123 // Find the start of the return type. 1125 // Find the start of the return type.
1124 for ($x += 1; $x < $numTokens; $x++) { 1126 for ($x += 1; $x < $numTokens; $x++) {
1125 if (is_array($tokens[$x]) === true 1127 if (is_array($tokens[$x]) === true
1126 && isset(Util\Tokens::$emptyTokens[$tokens[$x][0]]) === true 1128 && isset(Util\Tokens::$emptyTokens[$tokens[$x][0]]) === true
1127 ) { 1129 ) {
1128 // Whitespace or coments before the return type. 1130 // Whitespace or comments before the return type.
1129 continue; 1131 continue;
1130 } 1132 }
1131 1133
1132 if (is_array($tokens[$x]) === false && $tokens[$x] === '?') { 1134 if (is_array($tokens[$x]) === false && $tokens[$x] === '?') {
1133 // Found a nullable operator, so skip it. 1135 // Found a nullable operator, so skip it.
1279 T_NS_SEPARATOR => true, 1281 T_NS_SEPARATOR => true,
1280 T_USE => true, 1282 T_USE => true,
1281 T_NAMESPACE => true, 1283 T_NAMESPACE => true,
1282 T_PAAMAYIM_NEKUDOTAYIM => true, 1284 T_PAAMAYIM_NEKUDOTAYIM => true,
1283 ]; 1285 ];
1286
1284 if (isset($context[$finalTokens[$lastNotEmptyToken]['code']]) === true) { 1287 if (isset($context[$finalTokens[$lastNotEmptyToken]['code']]) === true) {
1285 // Special case for syntax like: return new self 1288 // Special case for syntax like: return new self
1286 // where self should not be a string. 1289 // where self should not be a string.
1287 if ($finalTokens[$lastNotEmptyToken]['code'] === T_NEW 1290 if ($finalTokens[$lastNotEmptyToken]['code'] === T_NEW
1288 && strtolower($token[1]) === 'self' 1291 && strtolower($token[1]) === 'self'