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


PHP PHP_CodeSniffer_File::removeTokenListener方法代码示例

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


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

示例1: process

 /**
  * Processes this test, when one of its tokens is encountered.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
  * @param int                  $stackPtr  The position of the current token
  *                                        in the stack passed in $tokens.
  *
  * @return void
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $groups = $this->getGroups();
     if (empty($groups)) {
         $phpcsFile->removeTokenListener($this, $this->register());
         return;
     }
     $tokens = $phpcsFile->getTokens();
     $token = $tokens[$stackPtr];
     $exclude = explode(',', $this->exclude);
     if (in_array($token['code'], array(T_CLOSE_SQUARE_BRACKET))) {
         $equal = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true);
         if ($tokens[$equal]['code'] !== T_EQUAL) {
             return;
             // This is not an assignment!
         }
     }
     // Instances: Multi-dimensional array, keyed by line
     $inst = array();
     // $foo = array( 'bar' => 'taz' );
     // $foo['bar'] = $taz;
     if (in_array($token['code'], array(T_CLOSE_SQUARE_BRACKET, T_DOUBLE_ARROW))) {
         if ($token['code'] == T_CLOSE_SQUARE_BRACKET) {
             $operator = $phpcsFile->findNext(array(T_EQUAL), $stackPtr + 1);
         } elseif ($token['code'] == T_DOUBLE_ARROW) {
             $operator = $stackPtr;
         }
         $keyIdx = $phpcsFile->findPrevious(array(T_WHITESPACE, T_CLOSE_SQUARE_BRACKET), $operator - 1, null, true);
         if (!is_numeric($tokens[$keyIdx]['content'])) {
             $key = trim($tokens[$keyIdx]['content'], '\'"');
             $valStart = $phpcsFile->findNext(array(T_WHITESPACE), $operator + 1, null, true);
             $valEnd = $phpcsFile->findNext(array(T_COMMA, T_SEMICOLON), $valStart + 1, null, false, null, true);
             $val = $phpcsFile->getTokensAsString($valStart, $valEnd - $valStart);
             $val = trim($val, '\'"');
             $inst[$key][] = array($val, $token['line']);
         }
     } elseif (in_array($token['code'], array(T_CONSTANT_ENCAPSED_STRING, T_DOUBLE_QUOTED_STRING))) {
         if (preg_match_all('#[\'"&]([a-z_]+)=([^\'"&]*)#i', $token['content'], $matches) <= 0) {
             return;
             // No assignments here, nothing to check
         }
         foreach ($matches[1] as $i => $_k) {
             $inst[$_k][] = array($matches[2][$i], $token['line']);
         }
     }
     if (empty($inst)) {
         return;
     }
     foreach ($groups as $groupName => $group) {
         if (in_array($groupName, $exclude)) {
             continue;
         }
         $callback = isset($group['callback']) && is_callable($group['callback']) ? $group['callback'] : array($this, 'callback');
         foreach ($inst as $key => $assignments) {
             foreach ($assignments as $occurance) {
                 list($val, $line) = $occurance;
                 if (!in_array($key, $group['keys'])) {
                     continue;
                 }
                 $output = call_user_func($callback, $key, $val, $line, $group);
                 if ($output === false || $output === null) {
                     continue;
                 } elseif ($output === true) {
                     $message = $group['message'];
                 } else {
                     $message = $output;
                 }
                 if ($group['type'] == 'warning') {
                     $addWhat = array($phpcsFile, 'addWarning');
                 } else {
                     $addWhat = array($phpcsFile, 'addError');
                 }
                 call_user_func($addWhat, $message, $stackPtr, $groupName, array($key, $val));
             }
         }
         // return; // Show one error only
     }
 }
开发者ID:sampath004,项目名称:WordPress-Coding-Standards,代码行数:87,代码来源:ArrayAssignmentRestrictionsSniff.php


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