Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Standards.php

function Standards::getInstalledStandards

Get a list of all coding standards installed.

Coding standards are directories located in the CodeSniffer/Standards directory. Valid coding standards include a Sniffs subdirectory.

Parameters

boolean $includeGeneric If true, the special "Generic": coding standard will be included if installed.

string $standardsDir A specific directory to look for standards: in. If not specified, PHP_CodeSniffer will look in its default locations.

Return value

array

See also

isInstalledStandard()

2 calls to Standards::getInstalledStandards()
Config::__set in vendor/squizlabs/php_codesniffer/src/Config.php
Set the value of an inaccessible property.
Standards::printInstalledStandards in vendor/squizlabs/php_codesniffer/src/Util/Standards.php
Prints out a list of installed coding standards.

File

vendor/squizlabs/php_codesniffer/src/Util/Standards.php, line 168

Class

Standards

Namespace

PHP_CodeSniffer\Util

Code

public static function getInstalledStandards($includeGeneric = false, $standardsDir = '') {
    $installedStandards = [];
    if ($standardsDir === '') {
        $installedPaths = self::getInstalledStandardPaths();
    }
    else {
        $installedPaths = [
            $standardsDir,
        ];
    }
    foreach ($installedPaths as $standardsDir) {
        // Check if the installed dir is actually a standard itself.
        $csFile = $standardsDir . '/ruleset.xml';
        if (is_file($csFile) === true) {
            $basename = basename($standardsDir);
            $installedStandards[$basename] = $basename;
            continue;
        }
        if (is_dir($standardsDir) === false) {
            // Doesn't exist.
            continue;
        }
        $di = new DirectoryIterator($standardsDir);
        $standardsInDir = [];
        foreach ($di as $file) {
            if ($file->isDir() === true && $file->isDot() === false) {
                $filename = $file->getFilename();
                // Ignore the special "Generic" standard.
                if ($includeGeneric === false && $filename === 'Generic') {
                    continue;
                }
                // Valid coding standard dirs include a ruleset.
                $csFile = $file->getPathname() . '/ruleset.xml';
                if (is_file($csFile) === true) {
                    $standardsInDir[$filename] = $filename;
                }
            }
        }
        natsort($standardsInDir);
        $installedStandards += $standardsInDir;
    }
    
    //end foreach
    return $installedStandards;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal