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


PHP PHP_CodeSniffer::getIgnorePatterns方法代码示例

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


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

示例1: process

 /**
  * Runs PHP_CodeSniffer over files and directories.
  *
  * @param array $values An array of values determined from CLI args.
  *
  * @return int The number of error and warning messages shown.
  * @see    getCommandLineValues()
  */
 public function process($values = array())
 {
     if (empty($values) === true) {
         $values = $this->getCommandLineValues();
     } else {
         $values = array_merge($this->getDefaults(), $values);
         $this->values = $values;
     }
     if ($values['generator'] !== '') {
         $phpcs = new PHP_CodeSniffer($values['verbosity']);
         if ($values['standard'] === null) {
             $values['standard'] = $this->validateStandard(null);
         }
         foreach ($values['standard'] as $standard) {
             $phpcs->generateDocs($standard, $values['sniffs'], $values['generator']);
         }
         exit(0);
     }
     // If no standard is supplied, get the default.
     $values['standard'] = $this->validateStandard($values['standard']);
     foreach ($values['standard'] as $standard) {
         if (PHP_CodeSniffer::isInstalledStandard($standard) === false) {
             // They didn't select a valid coding standard, so help them
             // out by letting them know which standards are installed.
             echo 'ERROR: the "' . $standard . '" coding standard is not installed. ';
             $this->printInstalledStandards();
             exit(2);
         }
     }
     if ($values['explain'] === true) {
         foreach ($values['standard'] as $standard) {
             $this->explainStandard($standard);
         }
         exit(0);
     }
     $phpcs = new PHP_CodeSniffer($values['verbosity'], null, null, null);
     $phpcs->setCli($this);
     $phpcs->initStandard($values['standard'], $values['sniffs']);
     $values = $this->values;
     $phpcs->setTabWidth($values['tabWidth']);
     $phpcs->setEncoding($values['encoding']);
     $phpcs->setInteractive($values['interactive']);
     // Set file extensions if they were specified. Otherwise,
     // let PHP_CodeSniffer decide on the defaults.
     if (empty($values['extensions']) === false) {
         $phpcs->setAllowedFileExtensions($values['extensions']);
     }
     // Set ignore patterns if they were specified.
     if (empty($values['ignored']) === false) {
         $ignorePatterns = array_merge($phpcs->getIgnorePatterns(), $values['ignored']);
         $phpcs->setIgnorePatterns($ignorePatterns);
     }
     // Set some convenience member vars.
     if ($values['errorSeverity'] === null) {
         $this->errorSeverity = PHPCS_DEFAULT_ERROR_SEV;
     } else {
         $this->errorSeverity = $values['errorSeverity'];
     }
     if ($values['warningSeverity'] === null) {
         $this->warningSeverity = PHPCS_DEFAULT_WARN_SEV;
     } else {
         $this->warningSeverity = $values['warningSeverity'];
     }
     if (empty($values['reports']) === true) {
         $values['reports']['full'] = $values['reportFile'];
         $this->values['reports'] = $values['reports'];
     }
     // Include bootstrap files.
     foreach ($values['bootstrap'] as $bootstrap) {
         include $bootstrap;
     }
     $phpcs->processFiles($values['files'], $values['local']);
     if (empty($values['files']) === true || $values['stdin'] !== null) {
         $fileContents = $values['stdin'];
         if ($fileContents === null) {
             // Check if they are passing in the file contents.
             $handle = fopen('php://stdin', 'r');
             stream_set_blocking($handle, true);
             $fileContents = stream_get_contents($handle);
             fclose($handle);
         }
         if ($fileContents === '') {
             // No files and no content passed in.
             echo 'ERROR: You must supply at least one file or directory to process.' . PHP_EOL . PHP_EOL;
             $this->printUsage();
             exit(2);
         } else {
             $phpcs->processFile('STDIN', $fileContents);
         }
     }
     // Interactive runs don't require a final report and it doesn't really
     // matter what the retun value is because we know it isn't being read
//.........这里部分代码省略.........
开发者ID:ghermans,项目名称:PHP_CodeSniffer,代码行数:101,代码来源:CLI.php

示例2: addWarning

 /**
  * Adds an warning to the warning stack.
  *
  * @param string $warning  The error message.
  * @param int    $stackPtr The stack position where the error occurred.
  * @param string $code     A violation code unique to the sniff message.
  * @param array  $data     Replacements for the warning message.
  * @param int    $severity The severity level for this warning. A value of 0
  *                         will be converted into the default severity level.
  *
  * @return void
  */
 public function addWarning($warning, $stackPtr, $code = '', $data = array(), $severity = 0)
 {
     // Don't bother doing any processing if warnings are just going to
     // be hidden in the reports anyway.
     if ($this->phpcs->cli->warningSeverity === 0) {
         return;
     }
     // Work out which sniff generated the warning.
     if (substr($code, 0, 9) === 'Internal.') {
         // Any internal message.
         $sniff = $code;
     } else {
         $parts = explode('_', $this->_activeListener);
         if (isset($parts[3]) === true) {
             $sniff = $parts[0] . '.' . $parts[2] . '.' . $parts[3];
             // Remove "Sniff" from the end.
             $sniff = substr($sniff, 0, -5);
         } else {
             $sniff = 'unknownSniff';
         }
         if ($code !== '') {
             $sniff .= '.' . $code;
         }
     }
     // Make sure this message type has not been set to "error".
     if (isset($this->ruleset[$sniff]['type']) === true && $this->ruleset[$sniff]['type'] === 'error') {
         // Pass this off to the error handler.
         $this->addError($warning, $stackPtr, $code, $data, $severity);
         return;
     }
     // Make sure we are interested in this severity level.
     if (isset($this->ruleset[$sniff]['severity']) === true) {
         $severity = $this->ruleset[$sniff]['severity'];
     } else {
         if ($severity === 0) {
             $severity = PHPCS_DEFAULT_WARN_SEV;
         }
     }
     if ($this->phpcs->cli->warningSeverity > $severity) {
         return;
     }
     // Make sure we are not ignoring this file.
     $patterns = $this->phpcs->getIgnorePatterns($sniff);
     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) {
             return;
         }
     }
     if ($stackPtr === null) {
         $lineNum = 1;
         $column = 1;
     } else {
         $lineNum = $this->_tokens[$stackPtr]['line'];
         $column = $this->_tokens[$stackPtr]['column'];
     }
     $this->_warningCount++;
     if ($this->_recordErrors === false) {
         if (isset($this->_warnings[$lineNum]) === false) {
             $this->_warnings[$lineNum] = 0;
         }
         $this->_warnings[$lineNum]++;
         return;
     }
     // Work out the warning message.
     if (isset($this->ruleset[$sniff]['message']) === true) {
         $warning = $this->ruleset[$sniff]['message'];
     }
     if (empty($data) === true) {
         $message = $warning;
     } else {
         $message = vsprintf($warning, $data);
     }
     if (isset($this->_warnings[$lineNum]) === false) {
         $this->_warnings[$lineNum] = array();
     }
     if (isset($this->_warnings[$lineNum][$column]) === false) {
         $this->_warnings[$lineNum][$column] = array();
     }
     $this->_warnings[$lineNum][$column][] = array('message' => $message, 'source' => $sniff, 'severity' => $severity);
 }
开发者ID:kameshwariv,项目名称:testexample,代码行数:96,代码来源:File.php

示例3: _addWarning

 /**
  * Adds an warning to the warning stack.
  *
  * @param string  $warning  The error message.
  * @param int     $line     The line on which the warning occurred.
  * @param int     $column   The column at which the warning occurred.
  * @param string  $code     A violation code unique to the sniff message.
  * @param array   $data     Replacements for the warning message.
  * @param int     $severity The severity level for this warning. A value of 0
  *                          will be converted into the default severity level.
  * @param boolean $fixable  Can the warning be fixed by the sniff?
  *
  * @return boolean
  */
 private function _addWarning($warning, $line, $column, $code, $data, $severity, $fixable)
 {
     if (isset(self::$_ignoredLines[$line]) === true) {
         return false;
     }
     // Work out which sniff generated the warning.
     if (substr($code, 0, 9) === 'Internal.') {
         // Any internal message.
         $sniff = $code;
         $sniffCode = $code;
     } else {
         $parts = explode('_', str_replace('\\', '_', $this->_activeListener));
         if (isset($parts[3]) === true) {
             $sniff = $parts[0] . '.' . $parts[2] . '.' . $parts[3];
             // Remove "Sniff" from the end.
             $sniff = substr($sniff, 0, -5);
         } else {
             $sniff = 'unknownSniff';
         }
         $sniffCode = $sniff;
         if ($code !== '') {
             $sniffCode .= '.' . $code;
         }
     }
     //end if
     // If we know this sniff code is being ignored for this file, return early.
     if (isset($this->_ignoredCodes[$sniffCode]) === true) {
         return false;
     }
     // Make sure this message type has not been set to "error".
     if (isset($this->ruleset[$sniffCode]['type']) === true && $this->ruleset[$sniffCode]['type'] === 'error') {
         // Pass this off to the error handler.
         return $this->_addError($warning, $line, $column, $code, $data, $severity, $fixable);
     } else {
         if ($this->phpcs->cli->warningSeverity === 0) {
             // Don't bother doing any processing as warnings are just going to
             // be hidden in the reports anyway.
             return false;
         }
     }
     // Make sure we are interested in this severity level.
     if (isset($this->ruleset[$sniffCode]['severity']) === true) {
         $severity = $this->ruleset[$sniffCode]['severity'];
     } else {
         if ($severity === 0) {
             $severity = PHPCS_DEFAULT_WARN_SEV;
         }
     }
     if ($this->phpcs->cli->warningSeverity > $severity) {
         return false;
     }
     // Make sure we are not ignoring this file.
     $patterns = $this->phpcs->getIgnorePatterns($sniffCode);
     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('\\,' => ',', '*' => '.*');
         // We assume a / directory separator, as do the exclude rules
         // most developers write, so we need a special case for any system
         // that is different.
         if (DIRECTORY_SEPARATOR === '\\') {
             $replacements['/'] = '\\\\';
         }
         $pattern = '`' . strtr($pattern, $replacements) . '`i';
         if (preg_match($pattern, $this->_file) === 1) {
             $this->_ignoredCodes[$sniffCode] = true;
             return false;
         }
     }
     //end foreach
     $this->_warningCount++;
     if ($fixable === true) {
         $this->_fixableCount++;
     }
     if ($this->_recordErrors === false) {
         if (isset($this->_warnings[$line]) === false) {
             $this->_warnings[$line] = 0;
         }
         $this->_warnings[$line]++;
         return true;
     }
     // Work out the warning message.
     if (isset($this->ruleset[$sniffCode]['message']) === true) {
         $warning = $this->ruleset[$sniffCode]['message'];
     }
     if (empty($data) === true) {
//.........这里部分代码省略.........
开发者ID:TomasVotruba,项目名称:PHP_CodeSniffer,代码行数:101,代码来源:File.php


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