当前位置: 首页>>代码示例>>PHP>>正文


PHP PHP_CodeSniffer::resolveSimpleToken方法代码示例

本文整理汇总了PHP中PHP_CodeSniffer::resolveSimpleToken方法的典型用法代码示例。如果您正苦于以下问题:PHP PHP_CodeSniffer::resolveSimpleToken方法的具体用法?PHP PHP_CodeSniffer::resolveSimpleToken怎么用?PHP PHP_CodeSniffer::resolveSimpleToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PHP_CodeSniffer的用法示例。


在下文中一共展示了PHP_CodeSniffer::resolveSimpleToken方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: tokenizeString

 /**
  * Creates an array of tokens when given some PHP code.
  *
  * Starts by using token_get_all() but does a lot of extra processing
  * to insert information about the context of the token.
  *
  * @param string $string  The string to tokenize.
  * @param string $eolChar The EOL character to use for splitting strings.
  *
  * @return array
  */
 public function tokenizeString($string, $eolChar = '\\n')
 {
     if (PHP_CODESNIFFER_VERBOSITY > 1) {
         echo "\t*** START PHP TOKENIZING ***" . PHP_EOL;
     }
     $tokens = @token_get_all($string);
     $finalTokens = array();
     $newStackPtr = 0;
     $numTokens = count($tokens);
     $insideInlineIf = false;
     for ($stackPtr = 0; $stackPtr < $numTokens; $stackPtr++) {
         $token = $tokens[$stackPtr];
         $tokenIsArray = is_array($token);
         if (PHP_CODESNIFFER_VERBOSITY > 1) {
             if ($tokenIsArray === true) {
                 $type = token_name($token[0]);
                 $content = str_replace($eolChar, "[30;1m\\n[0m", $token[1]);
             } else {
                 $newToken = PHP_CodeSniffer::resolveSimpleToken($token);
                 $type = $newToken['type'];
                 $content = $token;
             }
             $content = str_replace(' ', "[30;1m·[0m", $content);
             echo "\tProcess token {$stackPtr}: {$type} => {$content}" . PHP_EOL;
         }
         /*
             If we are using \r\n newline characters, the \r and \n are sometimes
             split over two tokens. This normally occurs after comments. We need
             to merge these two characters together so that our line endings are
             consistent for all lines.
         */
         if ($tokenIsArray === true && substr($token[1], -1) === "\r") {
             if (isset($tokens[$stackPtr + 1]) === true && is_array($tokens[$stackPtr + 1]) === true && $tokens[$stackPtr + 1][1][0] === "\n") {
                 $token[1] .= "\n";
                 if ($tokens[$stackPtr + 1][1] === "\n") {
                     // The next token's content has been merged into this token,
                     // so we can skip it.
                     $stackPtr++;
                 } else {
                     $tokens[$stackPtr + 1][1] = substr($tokens[$stackPtr + 1][1], 1);
                 }
             }
         }
         //end if
         /*
             If this is a double quoted string, PHP will tokenise the whole
             thing which causes problems with the scope map when braces are
             within the string. So we need to merge the tokens together to
             provide a single string.
         */
         if ($tokenIsArray === false && $token === '"') {
             $tokenContent = '"';
             $nestedVars = array();
             for ($i = $stackPtr + 1; $i < $numTokens; $i++) {
                 $subTokenIsArray = is_array($tokens[$i]);
                 if ($subTokenIsArray === true) {
                     $tokenContent .= $tokens[$i][1];
                     if ($tokens[$i][1] === '{' && $tokens[$i][0] !== T_ENCAPSED_AND_WHITESPACE) {
                         $nestedVars[] = $i;
                     }
                 } else {
                     $tokenContent .= $tokens[$i];
                     if ($tokens[$i] === '}') {
                         array_pop($nestedVars);
                     }
                 }
                 if ($subTokenIsArray === false && $tokens[$i] === '"' && empty($nestedVars) === true) {
                     // We found the other end of the double quoted string.
                     break;
                 }
             }
             //end for
             $stackPtr = $i;
             // Convert each line within the double quoted string to a
             // new token, so it conforms with other multiple line tokens.
             $tokenLines = explode($eolChar, $tokenContent);
             $numLines = count($tokenLines);
             $newToken = array();
             for ($j = 0; $j < $numLines; $j++) {
                 $newToken['content'] = $tokenLines[$j];
                 if ($j === $numLines - 1) {
                     if ($tokenLines[$j] === '') {
                         break;
                     }
                 } else {
                     $newToken['content'] .= $eolChar;
                 }
                 $newToken['code'] = T_DOUBLE_QUOTED_STRING;
                 $newToken['type'] = 'T_DOUBLE_QUOTED_STRING';
//.........这里部分代码省略.........
开发者ID:dereuromark,项目名称:cakephp-codesniffer,代码行数:101,代码来源:PHP.php


注:本文中的PHP_CodeSniffer::resolveSimpleToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。