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


PHP PHP_CodeSniffer::getInstalledStandards方法代码示例

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


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

示例1: suite

 /**
  * Add all sniff unit tests into a test suite.
  *
  * Sniff unit tests are found by recursing through the 'Tests' directory
  * of each installed coding standard.
  *
  * @return PHPUnit_Framework_TestSuite
  */
 public static function suite()
 {
     $suite = new PHPUnit_Framework_TestSuite('PHP CodeSniffer Standards');
     $isInstalled = !is_file(dirname(__FILE__) . '/../../CodeSniffer.php');
     if ($isInstalled === false) {
         // We have not been installed.
         $standardsDir = realpath(dirname(__FILE__) . '/../../CodeSniffer/Standards');
     } else {
         $standardsDir = '';
     }
     $standards = PHP_CodeSniffer::getInstalledStandards(true, $standardsDir);
     foreach ($standards as $standard) {
         if ($isInstalled === false) {
             $standardDir = realpath($standardsDir . '/' . $standard . '/Tests/');
         } else {
             $standardDir = dirname(__FILE__) . '/' . $standard . '/Tests/';
         }
         if (is_dir($standardDir) === false) {
             // No tests for this standard.
             continue;
         }
         $di = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($standardDir));
         foreach ($di as $file) {
             // Skip hidden files.
             if (substr($file->getFilename(), 0, 1) === '.') {
                 continue;
             }
             // Tests must have the extention 'php'.
             $parts = explode('.', $file);
             $ext = array_pop($parts);
             if ($ext !== 'php') {
                 continue;
             }
             $filePath = realpath($file->getPathname());
             if ($isInstalled === false) {
                 $className = str_replace($standardDir . DIRECTORY_SEPARATOR, '', $filePath);
             } else {
                 $className = str_replace(dirname(__FILE__) . DIRECTORY_SEPARATOR, '', $filePath);
             }
             $className = substr($className, 0, -4);
             $className = str_replace(DIRECTORY_SEPARATOR, '_', $className);
             if ($isInstalled === false) {
                 $className = $standard . '_Tests_' . $className;
             }
             $niceName = substr($className, strrpos($className, '_') + 1, -8);
             include_once $filePath;
             $class = new $className($niceName);
             $suite->addTest($class);
         }
         //end foreach
     }
     //end foreach
     return $suite;
 }
开发者ID:resid,项目名称:PHP_CodeSniffer,代码行数:62,代码来源:AllSniffs.php

示例2: suite

 /**
  * Add all sniff unit tests into a test suite.
  *
  * Sniff unit tests are found by recursing through the 'Tests' directory
  * of each installed coding standard.
  *
  * @return PHPUnit_Framework_TestSuite
  */
 public static function suite()
 {
     $suite = new PHPUnit_Framework_TestSuite('PHP CodeSniffer Standards');
     $isInstalled = !is_file(dirname(__FILE__) . '/../../CodeSniffer.php');
     $installedPaths = PHP_CodeSniffer::getInstalledStandardPaths();
     foreach ($installedPaths as $path) {
         $path = realpath($path);
         $origPath = $path;
         $standards = PHP_CodeSniffer::getInstalledStandards(true, $path);
         // If the test is running PEAR installed, the built-in standards
         // are split into different directories; one for the sniffs and
         // a different file system location for tests.
         if ($isInstalled === true && is_dir($path . DIRECTORY_SEPARATOR . 'Generic') === true) {
             $path = dirname(__FILE__);
         }
         foreach ($standards as $standard) {
             $testsDir = $path . DIRECTORY_SEPARATOR . $standard . DIRECTORY_SEPARATOR . 'Tests' . DIRECTORY_SEPARATOR;
             if (is_dir($testsDir) === false) {
                 // No tests for this standard.
                 continue;
             }
             $di = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($testsDir));
             foreach ($di as $file) {
                 // Skip hidden files.
                 if (substr($file->getFilename(), 0, 1) === '.') {
                     continue;
                 }
                 // Tests must have the extension 'php'.
                 $parts = explode('.', $file);
                 $ext = array_pop($parts);
                 if ($ext !== 'php') {
                     continue;
                 }
                 $filePath = $file->getPathname();
                 $className = str_replace($path . DIRECTORY_SEPARATOR, '', $filePath);
                 $className = substr($className, 0, -4);
                 $className = str_replace(DIRECTORY_SEPARATOR, '_', $className);
                 // Include the sniff here so tests can use it in their setup() methods.
                 $parts = explode('_', $className);
                 $sniffPath = $origPath . DIRECTORY_SEPARATOR . $parts[0] . DIRECTORY_SEPARATOR . 'Sniffs' . DIRECTORY_SEPARATOR . $parts[2] . DIRECTORY_SEPARATOR . $parts[3];
                 $sniffPath = substr($sniffPath, 0, -8) . 'Sniff.php';
                 include_once $sniffPath;
                 include_once $filePath;
                 $GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'][$className] = $path;
                 $suite->addTestSuite($className);
             }
             //end foreach
         }
         //end foreach
     }
     //end foreach
     return $suite;
 }
开发者ID:kmiku7,项目名称:PHP_CodeSniffer-2.3.2-annotated,代码行数:61,代码来源:AllSniffs.php

示例3: showCodestyleStandards

 /**
  * Show the available coding standards
  *
  * @param array $options
  */
 public function showCodestyleStandards($options = [])
 {
     $phpcs = new \PHP_CodeSniffer();
     $standards = $phpcs->getInstalledStandards();
     sort($standards);
     if (!$options['no-ansi']) {
         array_walk($standards, function (&$value) {
             $value = "<fg=green>{$value}</fg=green>";
         });
     }
     $last = array_pop($standards);
     $this->say("Installed coding standards are " . implode(', ', $standards) . " and " . $last);
 }
开发者ID:GreenCape,项目名称:robo,代码行数:18,代码来源:CodeSnifferCommands.php

示例4: suite

 /**
  * Add all sniff unit tests into a test suite.
  *
  * Sniff unit tests are found by recursing through the 'Tests' directory
  * of each installed coding standard.
  *
  * @return PHPUnit_Framework_TestSuite
  */
 public static function suite()
 {
     $suite = new PHPUnit_Framework_TestSuite('PHP CodeSniffer Standards');
     $isInstalled = !is_file(dirname(__FILE__) . '/../../CodeSniffer.php');
     if ($isInstalled === false) {
         // We have not been installed.
         $standardsDir = realpath(dirname(__FILE__) . '/../../CodeSniffer/Standards');
     } else {
         $standardsDir = '';
     }
     $standards = PHP_CodeSniffer::getInstalledStandards(true, $standardsDir);
     foreach ($standards as $standard) {
         if ($isInstalled === false) {
             $standardDir = $standardsDir . DIRECTORY_SEPARATOR . $standard . DIRECTORY_SEPARATOR . 'Tests' . DIRECTORY_SEPARATOR;
         } else {
             $standardDir = dirname(__FILE__) . DIRECTORY_SEPARATOR . $standard . DIRECTORY_SEPARATOR . 'Tests' . DIRECTORY_SEPARATOR;
         }
         if (is_dir($standardDir) === false) {
             // No tests for this standard.
             continue;
         }
         // Locate the actual directory that contains the standard's tests.
         // This is individual to each standard as they could be symlinked in.
         $baseDir = dirname(dirname($standardDir));
         $di = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($standardDir));
         foreach ($di as $file) {
             // Skip hidden files.
             if (substr($file->getFilename(), 0, 1) === '.') {
                 continue;
             }
             // Tests must have the extension 'php'.
             $parts = explode('.', $file);
             $ext = array_pop($parts);
             if ($ext !== 'php') {
                 continue;
             }
             $filePath = $file->getPathname();
             $className = str_replace($baseDir . DIRECTORY_SEPARATOR, '', $filePath);
             $className = substr($className, 0, -4);
             $className = str_replace(DIRECTORY_SEPARATOR, '_', $className);
             include_once $filePath;
             $class = new $className('getErrorList');
             $suite->addTest($class);
         }
         //end foreach
     }
     //end foreach
     return $suite;
 }
开发者ID:austinpapp,项目名称:push-notifications-temp,代码行数:57,代码来源:AllSniffs.php

示例5: main

 /**
  * Executes PHP code sniffer against PhingFile or a FileSet
  */
 public function main()
 {
     if (!class_exists('PHP_CodeSniffer')) {
         @(include_once 'PHP/CodeSniffer.php');
         if (!class_exists('PHP_CodeSniffer')) {
             throw new BuildException("This task requires the PHP_CodeSniffer package installed and available on the include path", $this->getLocation());
         }
     }
     /**
      * Determine PHP_CodeSniffer version number
      */
     if (!$this->skipversioncheck) {
         if (defined('PHP_CodeSniffer::VERSION')) {
             preg_match('/\\d\\.\\d\\.\\d/', PHP_CodeSniffer::VERSION, $version);
         } else {
             preg_match('/\\d\\.\\d\\.\\d/', shell_exec('phpcs --version'), $version);
         }
         if (version_compare($version[0], '1.2.2') < 0) {
             throw new BuildException('PhpCodeSnifferTask requires PHP_CodeSniffer version >= 1.2.2', $this->getLocation());
         }
     }
     if (!isset($this->file) and count($this->filesets) == 0) {
         throw new BuildException("Missing either a nested fileset or attribute 'file' set");
     }
     if (count($this->formatters) == 0) {
         // turn legacy format attribute into formatter
         $fmt = new PhpCodeSnifferTask_FormatterElement();
         $fmt->setType($this->format);
         $fmt->setUseFile(false);
         $this->formatters[] = $fmt;
     }
     $fileList = array();
     if (!isset($this->file)) {
         $project = $this->getProject();
         foreach ($this->filesets as $fs) {
             $ds = $fs->getDirectoryScanner($project);
             $files = $ds->getIncludedFiles();
             $dir = $fs->getDir($this->project)->getAbsolutePath();
             foreach ($files as $file) {
                 $fileList[] = $dir . DIRECTORY_SEPARATOR . $file;
             }
         }
     } else {
         $fileList[] = $this->file->getPath();
     }
     $cwd = getcwd();
     // Save command line arguments because it confuses PHPCS (version 1.3.0)
     $oldArgs = $_SERVER['argv'];
     $_SERVER['argv'] = array();
     $_SERVER['argc'] = 0;
     include_once 'phing/tasks/ext/phpcs/PhpCodeSnifferTask_Wrapper.php';
     $codeSniffer = new PhpCodeSnifferTask_Wrapper($this->verbosity, $this->tabWidth, $this->encoding);
     $codeSniffer->setAllowedFileExtensions($this->allowedFileExtensions);
     if ($this->allowedTypes) {
         PhpCodeSnifferTask_Wrapper::$allowedTypes = $this->allowedTypes;
     }
     if (is_array($this->ignorePatterns)) {
         $codeSniffer->setIgnorePatterns($this->ignorePatterns);
     }
     foreach ($this->configData as $configData) {
         $codeSniffer->setConfigData($configData->getName(), $configData->getValue(), true);
     }
     /*
      * Verifying if standard is installed only after setting config data.
      * Custom standard paths could be provided via installed_paths config parameter.
      */
     foreach ($this->standards 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.
             $installedStandards = PHP_CodeSniffer::getInstalledStandards();
             $numStandards = count($installedStandards);
             $errMsg = '';
             if ($numStandards === 0) {
                 $errMsg = 'No coding standards are installed.';
             } else {
                 $lastStandard = array_pop($installedStandards);
                 if ($numStandards === 1) {
                     $errMsg = 'The only coding standard installed is ' . $lastStandard;
                 } else {
                     $standardList = implode(', ', $installedStandards);
                     $standardList .= ' and ' . $lastStandard;
                     $errMsg = 'The installed coding standards are ' . $standardList;
                 }
             }
             throw new BuildException('ERROR: the "' . $standard . '" coding standard is not installed. ' . $errMsg, $this->getLocation());
         }
     }
     if (!$this->showWarnings) {
         $codeSniffer->cli->warningSeverity = 0;
     }
     // nasty integration hack
     $values = $codeSniffer->cli->getDefaults();
     $_SERVER['argv'] = array('t');
     $_SERVER['argc'] = 1;
     foreach ($this->formatters as $fe) {
         $output = $fe->getUseFile() ? $fe->getOutFile() : null;
//.........这里部分代码省略.........
开发者ID:continuousphptest,项目名称:workflow.test,代码行数:101,代码来源:PhpCodeSnifferTask.php

示例6: printInstalledStandards

 /**
  * Prints out a list of installed coding standards.
  *
  * @return void
  */
 public function printInstalledStandards()
 {
     $installedStandards = PHP_CodeSniffer::getInstalledStandards();
     $numStandards = count($installedStandards);
     if ($numStandards === 0) {
         echo 'No coding standards are installed.' . PHP_EOL;
     } else {
         $lastStandard = array_pop($installedStandards);
         if ($numStandards === 1) {
             echo "The only coding standard installed is {$lastStandard}" . PHP_EOL;
         } else {
             $standardList = implode(', ', $installedStandards);
             $standardList .= ' and ' . $lastStandard;
             echo 'The installed coding standards are ' . $standardList . PHP_EOL;
         }
     }
 }
开发者ID:CobaltBlueDW,项目名称:oddsandends,代码行数:22,代码来源:CLI.php

示例7: setStandard

 /**
  * Sets the coding standard to test for
  *
  * @param string $standard The coding standard
  *
  * @return void
  */
 public function setStandard($standard)
 {
     if (!class_exists('PHP_CodeSniffer')) {
         include_once 'PHP/CodeSniffer.php';
     }
     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.
         $installedStandards = PHP_CodeSniffer::getInstalledStandards();
         $numStandards = count($installedStandards);
         $errMsg = '';
         if ($numStandards === 0) {
             $errMsg = 'No coding standards are installed.';
         } else {
             $lastStandard = array_pop($installedStandards);
             if ($numStandards === 1) {
                 $errMsg = 'The only coding standard installed is ' . $lastStandard;
             } else {
                 $standardList = implode(', ', $installedStandards);
                 $standardList .= ' and ' . $lastStandard;
                 $errMsg = 'The installed coding standards are ' . $standardList;
             }
         }
         throw new BuildException('ERROR: the "' . $standard . '" coding standard is not installed. ' . $errMsg, $this->getLocation());
     }
     $this->standard = $standard;
 }
开发者ID:hkilter,项目名称:OpenSupplyChains,代码行数:34,代码来源:PhpCodeSnifferTask.php

示例8: validateStandard

 /**
  * Convert the passed standards into valid standards.
  *
  * Checks things like default values and case.
  *
  * @param array $standards The standards to validate.
  *
  * @return array
  */
 public function validateStandard($standards)
 {
     if ($standards === null) {
         // They did not supply a standard to use.
         // Try to get the default from the config system.
         $standard = PHP_CodeSniffer::getConfigData('default_standard');
         if ($standard === null) {
             // Product default standard.
             $standard = 'PEAR';
         }
         return array($standard);
     }
     $cleaned = array();
     // Check if the standard name is valid, or if the case is invalid.
     $installedStandards = PHP_CodeSniffer::getInstalledStandards();
     foreach ($standards as $standard) {
         foreach ($installedStandards as $validStandard) {
             if (strtolower($standard) === strtolower($validStandard)) {
                 $standard = $validStandard;
                 break;
             }
         }
         $cleaned[] = $standard;
     }
     return $cleaned;
 }
开发者ID:TheTypoMaster,项目名称:SPHERE-Framework,代码行数:35,代码来源:CLI.php

示例9: _standards

 /**
  * CodeSnifferShell::_standards()
  *
  * @return array
  */
 protected function _standards()
 {
     include_once 'PHP/CodeSniffer.php';
     return PHP_CodeSniffer::getInstalledStandards();
 }
开发者ID:dereuromark,项目名称:cakephp-codesniffer,代码行数:10,代码来源:CodeSnifferShell.php


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