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