PHP_CodeSniffer::isInstalledStandard PHP Method

isInstalledStandard() public static method

Coding standards are directories located in the CodeSniffer/Standards directory. Valid coding standards include a ruleset.xml file.
See also: getInstalledStandards()
public static isInstalledStandard ( string $standard ) : boolean
$standard string The name of the coding standard.
return boolean
    public static function isInstalledStandard($standard)
    {
        $path = self::getInstalledStandardPath($standard);
        if ($path !== null && strpos($path, 'ruleset.xml') !== false) {
            return true;
        } else {
            // This could be a custom standard, installed outside our
            // standards directory.
            $standard = self::realPath($standard);
            // Might be an actual ruleset file itself.
            // If it has an XML extension, let's at least try it.
            if (is_file($standard) === true && (substr(strtolower($standard), -4) === '.xml' || substr(strtolower($standard), -9) === '.xml.dist')) {
                return true;
            }
            // If it is a directory with a ruleset.xml file in it,
            // it is a standard.
            $ruleset = rtrim($standard, ' /\\') . DIRECTORY_SEPARATOR . 'ruleset.xml';
            if (is_file($ruleset) === true) {
                return true;
            }
        }
        //end if
        return false;
    }

Usage Example

Esempio n. 1
0
 /**
  * Convert the passed standard into a valid standard.
  *
  * Checks things like default values and case.
  *
  * @param string $standard The standard to validate.
  *
  * @return string
  */
 public function validateStandard($standard)
 {
     if ($standard === 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) {
             $standard = 'PEAR';
         }
     }
     // Check if the standard name is valid. If not, check that the case
     // was not entered incorrectly.
     if (PHP_CodeSniffer::isInstalledStandard($standard) === false) {
         $installedStandards = PHP_CodeSniffer::getInstalledStandards();
         foreach ($installedStandards as $validStandard) {
             if (strtolower($standard) === strtolower($validStandard)) {
                 $standard = $validStandard;
                 break;
             }
         }
     }
     return $standard;
 }
All Usage Examples Of PHP_CodeSniffer::isInstalledStandard