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


PHP PHP_CodeSniffer::setSniffProperty方法代码示例

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


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

示例1: start

 /**
  * Starts the stack traversal and tells listeners when tokens are found.
  *
  * @param string $contents The contents to parse. If NULL, the content
  *                         is taken from the file system.
  *
  * @return void
  */
 public function start($contents = null)
 {
     $this->_parse($contents);
     if (PHP_CODESNIFFER_VERBOSITY > 2) {
         echo "\t*** START TOKEN PROCESSING ***" . PHP_EOL;
     }
     $foundCode = false;
     $ignoring = false;
     // Foreach of the listeners that have registered to listen for this
     // token, get them to process it.
     foreach ($this->_tokens as $stackPtr => $token) {
         // Check for ignored lines.
         if ($token['code'] === T_COMMENT) {
             if (strpos($token['content'], '@codingStandardsIgnoreStart') !== false) {
                 $ignoring = true;
             } else {
                 if (strpos($token['content'], '@codingStandardsIgnoreEnd') !== false) {
                     $ignoring = false;
                     // Ignore this comment too.
                     $this->_ignoredLines[$token['line']] = true;
                 } else {
                     if (strpos($token['content'], '@codingStandardsIgnoreFile') !== false) {
                         // Ignoring the whole file, just a little late.
                         $this->_errors = array();
                         $this->_warnings = array();
                         $this->_errorCount = 0;
                         $this->_warningCount = 0;
                         return;
                     } else {
                         if (strpos($token['content'], '@codingStandardsChangeSetting') !== false) {
                             $start = strpos($token['content'], '@codingStandardsChangeSetting');
                             $comment = substr($token['content'], $start + 30);
                             $parts = explode(' ', $comment);
                             $sniffParts = explode('.', $parts[0]);
                             $listenerClass = $sniffParts[0] . '_Sniffs_' . $sniffParts[1] . '_' . $sniffParts[2] . 'Sniff';
                             $this->phpcs->setSniffProperty($listenerClass, $parts[1], $parts[2]);
                         }
                     }
                 }
             }
         }
         if ($ignoring === true) {
             $this->_ignoredLines[$token['line']] = true;
             continue;
         }
         if (PHP_CODESNIFFER_VERBOSITY > 2) {
             $type = $token['type'];
             $content = str_replace($this->eolChar, '\\n', $token['content']);
             echo "\t\tProcess token {$stackPtr}: {$type} => {$content}" . PHP_EOL;
         }
         $tokenType = $token['code'];
         if ($tokenType !== T_INLINE_HTML) {
             $foundCode = true;
         }
         if (isset($this->_listeners[$tokenType]) === false) {
             continue;
         }
         foreach ($this->_listeners[$tokenType] as $listenerData) {
             // Make sure this sniff supports the tokenizer
             // we are currently using.
             $listener = $listenerData['listener'];
             $class = $listenerData['class'];
             if (in_array($this->tokenizerType, $listenerData['tokenizers']) === false) {
                 continue;
             }
             // If the file path matches one of our ignore patterns, skip it.
             $parts = explode('_', $class);
             if (isset($parts[3]) === true) {
                 $source = $parts[0] . '.' . $parts[2] . '.' . substr($parts[3], 0, -5);
                 $patterns = $this->phpcs->getIgnorePatterns($source);
                 foreach ($patterns as $pattern => $type) {
                     // While there is support for a type of each pattern
                     // (absolute or relative) we don't actually support it here.
                     $replacements = array('\\,' => ',', '*' => '.*');
                     $pattern = strtr($pattern, $replacements);
                     if (preg_match("|{$pattern}|i", $this->_file) === 1) {
                         continue 2;
                     }
                 }
             }
             $this->setActiveListener($class);
             if (PHP_CODESNIFFER_VERBOSITY > 2) {
                 $startTime = microtime(true);
                 echo "\t\t\tProcessing " . $this->_activeListener . '... ';
             }
             $listener->process($this, $stackPtr);
             if (PHP_CODESNIFFER_VERBOSITY > 2) {
                 $timeTaken = microtime(true) - $startTime;
                 if (isset($this->_listenerTimes[$this->_activeListener]) === false) {
                     $this->_listenerTimes[$this->_activeListener] = 0;
                 }
                 $this->_listenerTimes[$this->_activeListener] += $timeTaken;
//.........这里部分代码省略.........
开发者ID:kameshwariv,项目名称:testexample,代码行数:101,代码来源:File.php

示例2: start

 /**
  * Starts the stack traversal and tells listeners when tokens are found.
  *
  * @param string $contents The contents to parse. If NULL, the content
  *                         is taken from the file system.
  *
  * @return void
  */
 public function start($contents = null)
 {
     $this->_errors = array();
     $this->_warnings = array();
     $this->_errorCount = 0;
     $this->_warningCount = 0;
     $this->_fixableCount = 0;
     // Reset the ignored lines because lines numbers may have changed
     // if we are fixing this file.
     self::$_ignoredLines = array();
     try {
         $this->eolChar = self::detectLineEndings($this->_file, $contents);
     } catch (PHP_CodeSniffer_Exception $e) {
         $this->addWarning($e->getMessage(), null, 'Internal.DetectLineEndings');
         return;
     }
     // If this is standard input, see if a filename was passed in as well.
     // This is done by including: phpcs_input_file: [file path]
     // as the first line of content.
     if ($this->_file === 'STDIN' && $contents !== null) {
         if (substr($contents, 0, 17) === 'phpcs_input_file:') {
             $eolPos = strpos($contents, $this->eolChar);
             $filename = trim(substr($contents, 17, $eolPos - 17));
             $contents = substr($contents, $eolPos + strlen($this->eolChar));
             $this->_file = $filename;
         }
     }
     $this->_parse($contents);
     $this->fixer->startFile($this);
     if (PHP_CODESNIFFER_VERBOSITY > 2) {
         echo "\t*** START TOKEN PROCESSING ***" . PHP_EOL;
     }
     $foundCode = false;
     $listeners = $this->phpcs->getSniffs();
     $listenerIgnoreTo = array();
     $inTests = defined('PHP_CODESNIFFER_IN_TESTS');
     // Foreach of the listeners that have registered to listen for this
     // token, get them to process it.
     foreach ($this->_tokens as $stackPtr => $token) {
         // Check for ignored lines.
         if ($token['code'] === T_COMMENT || $token['code'] === T_DOC_COMMENT_TAG || $inTests === true && $token['code'] === T_INLINE_HTML) {
             if (strpos($token['content'], '@codingStandards') !== false) {
                 if (strpos($token['content'], '@codingStandardsIgnoreFile') !== false) {
                     // Ignoring the whole file, just a little late.
                     $this->_errors = array();
                     $this->_warnings = array();
                     $this->_errorCount = 0;
                     $this->_warningCount = 0;
                     $this->_fixableCount = 0;
                     return;
                 } else {
                     if (strpos($token['content'], '@codingStandardsChangeSetting') !== false) {
                         $start = strpos($token['content'], '@codingStandardsChangeSetting');
                         $comment = substr($token['content'], $start + 30);
                         $parts = explode(' ', $comment);
                         $sniffParts = explode('.', $parts[0]);
                         $listenerClass = $sniffParts[0] . '_Sniffs_' . $sniffParts[1] . '_' . $sniffParts[2] . 'Sniff';
                         $this->phpcs->setSniffProperty($listenerClass, $parts[1], $parts[2]);
                     }
                 }
                 //end if
             }
             //end if
         }
         //end if
         if (PHP_CODESNIFFER_VERBOSITY > 2) {
             $type = $token['type'];
             $content = PHP_CodeSniffer::prepareForOutput($token['content']);
             echo "\t\tProcess token {$stackPtr}: {$type} => {$content}" . PHP_EOL;
         }
         if ($token['code'] !== T_INLINE_HTML) {
             $foundCode = true;
         }
         if (isset($this->_listeners[$token['code']]) === false) {
             continue;
         }
         foreach ($this->_listeners[$token['code']] as $listenerData) {
             if (isset($this->_ignoredListeners[$listenerData['class']]) === true || isset($listenerIgnoreTo[$listenerData['class']]) === true && $listenerIgnoreTo[$listenerData['class']] > $stackPtr) {
                 // This sniff is ignoring past this token, or the whole file.
                 continue;
             }
             // Make sure this sniff supports the tokenizer
             // we are currently using.
             $class = $listenerData['class'];
             if (isset($listenerData['tokenizers'][$this->tokenizerType]) === false) {
                 continue;
             }
             // If the file path matches one of our ignore patterns, skip it.
             // While there is support for a type of each pattern
             // (absolute or relative) we don't actually support it here.
             foreach ($listenerData['ignore'] as $pattern) {
                 // We assume a / directory separator, as do the exclude rules
//.........这里部分代码省略.........
开发者ID:TomasVotruba,项目名称:PHP_CodeSniffer,代码行数:101,代码来源:File.php


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