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


PHP PHP_CodeSniffer_File::_ignoredLines方法代码示例

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


在下文中一共展示了PHP_CodeSniffer_File::_ignoredLines方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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->_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_File::_ignoredLines方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。