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


PHP PHP_CodeSniffer::rulesetDirs方法代码示例

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


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

示例1: initStandard

 /**
  * Initialise the standard that the run will use.
  *
  * @param string|array $standards    The set of code sniffs we are testing
  *                                   against.
  * @param array        $restrictions The sniff codes to restrict the
  *
  * @return void
  */
 public function initStandard($standards, array $restrictions = array())
 {
     $standards = (array) $standards;
     // Reset the members.
     $this->listeners = array();
     $this->sniffs = array();
     $this->ruleset = array();
     $this->_tokenListeners = array();
     self::$rulesetDirs = array();
     // Ensure this option is enabled or else line endings will not always
     // be detected properly for files created on a Mac with the /r line ending.
     ini_set('auto_detect_line_endings', true);
     $sniffs = array();
     foreach ($standards as $standard) {
         $installed = $this->getInstalledStandardPath($standard);
         if ($installed !== null) {
             $standard = $installed;
         } else {
             $standard = self::realpath($standard);
             if (is_dir($standard) === true && is_file(self::realpath($standard . DIRECTORY_SEPARATOR . 'ruleset.xml')) === true) {
                 $standard = self::realpath($standard . DIRECTORY_SEPARATOR . 'ruleset.xml');
             }
         }
         if (PHP_CODESNIFFER_VERBOSITY === 1) {
             $ruleset = simplexml_load_string(file_get_contents($standard));
             if ($ruleset !== false) {
                 $standardName = (string) $ruleset['name'];
             }
             echo "Registering sniffs in the {$standardName} standard... ";
             if (count($standards) > 1 || PHP_CODESNIFFER_VERBOSITY > 2) {
                 echo PHP_EOL;
             }
         }
         $sniffs = array_merge($sniffs, $this->processRuleset($standard));
     }
     //end foreach
     $sniffRestrictions = array();
     foreach ($restrictions as $sniffCode) {
         $parts = explode('.', strtolower($sniffCode));
         $sniffRestrictions[] = $parts[0] . '_sniffs_' . $parts[1] . '_' . $parts[2] . 'sniff';
     }
     $this->registerSniffs($sniffs, $sniffRestrictions);
     $this->populateTokenListeners();
     if (PHP_CODESNIFFER_VERBOSITY === 1) {
         $numSniffs = count($this->sniffs);
         echo "DONE ({$numSniffs} sniffs registered)" . PHP_EOL;
     }
 }
开发者ID:Makiss,项目名称:test_guestbook_mvc,代码行数:57,代码来源:CodeSniffer.php

示例2: process

 /**
  * Processes the files/directories that PHP_CodeSniffer was constructed with.
  *
  * @param string|array $files        The files and directories to process. For
  *                                   directories, each sub directory will also
  *                                   be traversed for source files.
  * @param string|array $standards    The set of code sniffs we are testing
  *                                   against.
  * @param array        $restrictions The sniff codes to restrict the
  *                                   violations to.
  * @param boolean      $local        If true, don't recurse into directories.
  *
  * @return void
  * @throws PHP_CodeSniffer_Exception If files or standard are invalid.
  */
 public function process($files, $standards, array $restrictions = array(), $local = false)
 {
     if (is_array($files) === false) {
         $files = array($files);
     }
     if (is_array($standards) === false) {
         $standards = array($standards);
     }
     // Reset the members.
     $this->listeners = array();
     $this->sniffs = array();
     $this->ruleset = array();
     $this->_tokenListeners = array();
     self::$rulesetDirs = array();
     // Ensure this option is enabled or else line endings will not always
     // be detected properly for files created on a Mac with the /r line ending.
     ini_set('auto_detect_line_endings', true);
     $sniffs = array();
     foreach ($standards as $standard) {
         $installed = $this->getInstalledStandardPath($standard);
         if ($installed !== null) {
             $standard = $installed;
         } else {
             if (is_dir($standard) === true && is_file(realpath($standard . '/ruleset.xml')) === true) {
                 $standard = realpath($standard . '/ruleset.xml');
             }
         }
         if (PHP_CODESNIFFER_VERBOSITY === 1) {
             $ruleset = simplexml_load_file($standard);
             if ($ruleset !== false) {
                 $standardName = (string) $ruleset['name'];
             }
             echo "Registering sniffs in the {$standardName} standard... ";
             if (count($standards) > 1 || PHP_CODESNIFFER_VERBOSITY > 2) {
                 echo PHP_EOL;
             }
         }
         $sniffs = array_merge($sniffs, $this->processRuleset($standard));
     }
     //end foreach
     $sniffRestrictions = array();
     foreach ($restrictions as $sniffCode) {
         $parts = explode('.', strtolower($sniffCode));
         $sniffRestrictions[] = $parts[0] . '_sniffs_' . $parts[1] . '_' . $parts[2] . 'sniff';
     }
     $this->registerSniffs($sniffs, $sniffRestrictions);
     $this->populateTokenListeners();
     if (PHP_CODESNIFFER_VERBOSITY === 1) {
         $numSniffs = count($this->sniffs);
         echo "DONE ({$numSniffs} sniffs registered)" . PHP_EOL;
     }
     // The SVN pre-commit calls process() to init the sniffs
     // and ruleset so there may not be any files to process.
     // But this has to come after that initial setup.
     if (empty($files) === true) {
         return;
     }
     $cliValues = $this->cli->getCommandLineValues();
     $showProgress = $cliValues['showProgress'];
     if (PHP_CODESNIFFER_VERBOSITY > 0) {
         echo 'Creating file list... ';
     }
     $todo = $this->getFilesToProcess($files, $local);
     $numFiles = count($todo);
     if (PHP_CODESNIFFER_VERBOSITY > 0) {
         echo "DONE ({$numFiles} files in queue)" . PHP_EOL;
     }
     $numProcessed = 0;
     $dots = 0;
     $maxLength = strlen($numFiles);
     $lastDir = '';
     foreach ($todo as $file) {
         $this->file = $file;
         $currDir = dirname($file);
         if ($lastDir !== $currDir) {
             if (PHP_CODESNIFFER_VERBOSITY > 0) {
                 echo 'Changing into directory ' . $currDir . PHP_EOL;
             }
             $lastDir = $currDir;
         }
         $phpcsFile = $this->processFile($file, null, $restrictions);
         $numProcessed++;
         if (PHP_CODESNIFFER_VERBOSITY > 0 || PHP_CODESNIFFER_INTERACTIVE === true || $showProgress === false) {
             continue;
         }
//.........这里部分代码省略.........
开发者ID:Flesh192,项目名称:magento,代码行数:101,代码来源:CodeSniffer.php


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