當前位置: 首頁>>代碼示例>>PHP>>正文


PHP PHP_CodeSniffer::standardiseToken方法代碼示例

本文整理匯總了PHP中PHP_CodeSniffer::standardiseToken方法的典型用法代碼示例。如果您正苦於以下問題:PHP PHP_CodeSniffer::standardiseToken方法的具體用法?PHP PHP_CodeSniffer::standardiseToken怎麽用?PHP PHP_CodeSniffer::standardiseToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PHP_CodeSniffer的用法示例。


在下文中一共展示了PHP_CodeSniffer::standardiseToken方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: tokenizeString


//.........這裏部分代碼省略.........
             $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';
                 $finalTokens[$newStackPtr] = $newToken;
                 $newStackPtr++;
             }
             // Continue, as we're done with this token.
             continue;
         }
         //end if
         /*
             If this is a heredoc, PHP will tokenise the whole
             thing which causes problems when heredocs don't
             contain real PHP code, which is almost never.
             We want to leave the start and end heredoc tokens
             alone though.
         */
         if ($tokenIsArray === true && $token[0] === T_START_HEREDOC) {
             // Add the start heredoc token to the final array.
             $finalTokens[$newStackPtr] = PHP_CodeSniffer::standardiseToken($token);
             // Check if this is actually a nowdoc and use a different token
             // to help the sniffs.
             $nowdoc = false;
             if ($token[1][3] === "'") {
                 $finalTokens[$newStackPtr]['code'] = T_START_NOWDOC;
                 $finalTokens[$newStackPtr]['type'] = 'T_START_NOWDOC';
                 $nowdoc = true;
             }
             $newStackPtr++;
             $tokenContent = '';
             for ($i = $stackPtr + 1; $i < $numTokens; $i++) {
                 $subTokenIsArray = is_array($tokens[$i]);
                 if ($subTokenIsArray === true && $tokens[$i][0] === T_END_HEREDOC) {
                     // We found the other end of the heredoc.
                     break;
                 }
                 if ($subTokenIsArray === true) {
                     $tokenContent .= $tokens[$i][1];
                 } else {
                     $tokenContent .= $tokens[$i];
                 }
             }
             $stackPtr = $i;
             // Convert each line within the heredoc 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] === '') {
開發者ID:sunnystone85,項目名稱:CsPCHookSugar,代碼行數:67,代碼來源:PHP.php

示例2: tokenizeString


//.........這裏部分代碼省略.........
             $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';
                 $finalTokens[$newStackPtr] = $newToken;
                 $newStackPtr++;
             }
             // Continue, as we're done with this token.
             continue;
         }
         //end if
         /*
             If this is a heredoc, PHP will tokenise the whole
             thing which causes problems when heredocs don't
             contain real PHP code, which is almost never.
             We want to leave the start and end heredoc tokens
             alone though.
         */
         if ($tokenIsArray === true && $token[0] === T_START_HEREDOC) {
             // Add the start heredoc token to the final array.
             $finalTokens[$newStackPtr] = PHP_CodeSniffer::standardiseToken($token);
             // Check if this is actually a nowdoc and use a different token
             // to help the sniffs.
             $nowdoc = false;
             if ($token[1][3] === "'") {
                 $finalTokens[$newStackPtr]['code'] = T_START_NOWDOC;
                 $finalTokens[$newStackPtr]['type'] = 'T_START_NOWDOC';
                 $nowdoc = true;
             }
             $newStackPtr++;
             $tokenContent = '';
             for ($i = $stackPtr + 1; $i < $numTokens; $i++) {
                 $subTokenIsArray = is_array($tokens[$i]);
                 if ($subTokenIsArray === true && $tokens[$i][0] === T_END_HEREDOC) {
                     // We found the other end of the heredoc.
                     break;
                 }
                 if ($subTokenIsArray === true) {
                     $tokenContent .= $tokens[$i][1];
                 } else {
                     $tokenContent .= $tokens[$i];
                 }
             }
             $stackPtr = $i;
             // Convert each line within the heredoc 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] === '') {
開發者ID:superstarrajini,項目名稱:cakepackages,代碼行數:67,代碼來源:PHP.php

示例3: _createTokenPattern

 /**
  * Creates a token pattern.
  *
  * @param string $str The tokens string that the pattern should match.
  *
  * @return array The pattern step.
  * @see _createSkipPattern()
  * @see _parse()
  */
 private function _createTokenPattern($str)
 {
     // Don't add a space after the closing php tag as it will add a new
     // whitespace token.
     $tokens = token_get_all('<?php ' . $str . '?>');
     // Remove the <?php tag from the front and the end php tag from the back.
     $tokens = array_slice($tokens, 1, count($tokens) - 2);
     foreach ($tokens as &$token) {
         $token = PHP_CodeSniffer::standardiseToken($token);
     }
     $patterns = array();
     foreach ($tokens as $patternInfo) {
         $patterns[] = array('type' => 'token', 'token' => $patternInfo['code'], 'value' => $patternInfo['content']);
     }
     return $patterns;
 }
開發者ID:vuchannguyen,項目名稱:web,代碼行數:25,代碼來源:AbstractPatternSniff.php

示例4: _parse

 /**
  * Processes the file and runs the PHP_CodeSniffer sniffs to verify that it
  * conforms with the tests.
  *
  * @return void
  * @throws PHP_CodeSniffer_Exception If the file could not be processed.
  */
 private function _parse()
 {
     $contents = file_get_contents($this->_file);
     $tokens = token_get_all($contents);
     $newStackPtr = 0;
     $numTokens = count($tokens);
     for ($stackPtr = 0; $stackPtr < $numTokens; $stackPtr++) {
         $token = $tokens[$stackPtr];
         // 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 (is_array($token) === false && $token === '"') {
             $tokenContent = '"';
             for ($i = $stackPtr + 1; $i < $numTokens; $i++) {
                 if (is_array($tokens[$i]) === true) {
                     $tokenContent .= $tokens[$i][1];
                 } else {
                     $tokenContent .= $tokens[$i];
                 }
                 if (is_array($tokens[$i]) === false && $tokens[$i] === '"') {
                     // We found the other end of the double quoted string.
                     break;
                 }
             }
             $stackPtr = $i;
             // Convert each line within the double quoted string to a
             // new token, so it conforms with other multiple line tokens.
             $tokenLines = explode("\n", $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'] .= "\n";
                 }
                 $newToken['code'] = T_DOUBLE_QUOTED_STRING;
                 $newToken['type'] = 'T_DOUBLE_QUOTED_STRING';
                 $this->_tokens[$newStackPtr] = $newToken;
                 $newStackPtr++;
             }
             // Continue, as we're done with this token.
             continue;
         }
         //end if
         // If this token has newlines in its content, split each line up
         // and create a new token for each line. We do this so it's easier
         // to asertain where errors occur on a line.
         if (is_array($token) === true && strpos($token[1], "\n") !== false) {
             $tokenLines = explode("\n", $token[1]);
             $numLines = count($tokenLines);
             for ($i = 0; $i < $numLines; $i++) {
                 $newToken['content'] = $tokenLines[$i];
                 if ($i === $numLines - 1) {
                     if ($tokenLines[$i] === '') {
                         break;
                     }
                 } else {
                     $newToken['content'] .= "\n";
                 }
                 $newToken['type'] = token_name($token[0]);
                 $newToken['code'] = $token[0];
                 $this->_tokens[$newStackPtr] = $newToken;
                 $newStackPtr++;
             }
         } else {
             $newToken = PHP_CodeSniffer::standardiseToken($token);
             // This is a special condition for T_ARRAY tokens use to
             // type hint function arguments as being arrays. We want to keep
             // the parenthsis map clean, so let's tag these tokens as
             // T_ARRAY_HINT.
             if ($newToken['code'] === T_ARRAY) {
                 // Recalculate number of tokens.
                 $numTokens = count($tokens);
                 for ($i = $stackPtr; $i < $numTokens; $i++) {
                     if (is_array($tokens[$i]) === false) {
                         if ($tokens[$i] === '(') {
                             break;
                         }
                     } else {
                         if ($tokens[$i][0] === T_VARIABLE) {
                             $newToken['code'] = T_ARRAY_HINT;
                             $newToken['type'] = 'T_ARRAY_HINT';
                             break;
                         }
                     }
                 }
             }
             $this->_tokens[$newStackPtr] = $newToken;
//.........這裏部分代碼省略.........
開發者ID:ookwudili,項目名稱:chisimba,代碼行數:101,代碼來源:File.php


注:本文中的PHP_CodeSniffer::standardiseToken方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。