PHP_CodeSniffer::getInstalledStandardPath PHP Method

getInstalledStandardPath() public static method

Coding standards are directories located in the CodeSniffer/Standards directory. Valid coding standards include a ruleset.xml file.
public static getInstalledStandardPath ( string $standard ) : string | null
$standard string The name of the coding standard.
return string | null
    public static function getInstalledStandardPath($standard)
    {
        $installedPaths = self::getInstalledStandardPaths();
        foreach ($installedPaths as $installedPath) {
            $standardPath = $installedPath . DIRECTORY_SEPARATOR . $standard;
            $path = self::realpath($standardPath . DIRECTORY_SEPARATOR . 'ruleset.xml');
            if (is_file($path) === true) {
                return $path;
            } else {
                if (self::isPharFile($standardPath) === true) {
                    $path = self::realpath($standardPath);
                    if ($path !== false) {
                        return $path;
                    }
                }
            }
        }
        return null;
    }

Usage Example

Esempio n. 1
0
 /**
  * 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');
     $baseDir = pathinfo(getcwd() . "/Ongr", PATHINFO_DIRNAME);
     \PHP_CodeSniffer::setConfigData('installed_paths', $baseDir);
     $path = pathinfo(\PHP_CodeSniffer::getInstalledStandardPath('Ongr'), PATHINFO_DIRNAME);
     $testsDir = $path . DIRECTORY_SEPARATOR . 'Tests' . DIRECTORY_SEPARATOR . 'Unit';
     $directoryIterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($testsDir));
     /** @var \SplFileInfo $fileinfo */
     foreach ($directoryIterator as $file) {
         // Skip hidden and extension must be php.
         if ($file->getFilename()[0] === '.' || pathinfo($file, PATHINFO_EXTENSION) !== 'php') {
             continue;
         }
         $className = str_replace([$baseDir . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR], ['', '\\'], substr($file, 0, -4));
         $suite->addTest(new $className('getErrorList'));
     }
     return $suite;
 }
All Usage Examples Of PHP_CodeSniffer::getInstalledStandardPath