當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。