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

Breadcrumb

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

function Ruleset::expandSniffDirectory

Expands a directory into a list of sniff files within.

Parameters

string $directory The path to a directory.:

int $depth How many nested processing steps we are in. This: is only used for debug output.

Return value

array

2 calls to Ruleset::expandSniffDirectory()
Ruleset::expandRulesetReference in vendor/squizlabs/php_codesniffer/src/Ruleset.php
Expands a ruleset reference into a list of sniff files.
Ruleset::processRuleset in vendor/squizlabs/php_codesniffer/src/Ruleset.php
Processes a single ruleset and returns a list of the sniffs it represents.

File

vendor/squizlabs/php_codesniffer/src/Ruleset.php, line 783

Class

Ruleset

Namespace

PHP_CodeSniffer

Code

private function expandSniffDirectory($directory, $depth = 0) {
    $sniffs = [];
    $rdi = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::FOLLOW_SYMLINKS);
    $di = new RecursiveIteratorIterator($rdi, 0, RecursiveIteratorIterator::CATCH_GET_CHILD);
    $dirLen = strlen($directory);
    foreach ($di as $file) {
        $filename = $file->getFilename();
        // Skip hidden files.
        if (substr($filename, 0, 1) === '.') {
            continue;
        }
        // We are only interested in PHP and sniff files.
        $fileParts = explode('.', $filename);
        if (array_pop($fileParts) !== 'php') {
            continue;
        }
        $basename = basename($filename, '.php');
        if (substr($basename, -5) !== 'Sniff') {
            continue;
        }
        $path = $file->getPathname();
        // Skip files in hidden directories within the Sniffs directory of this
        // standard. We use the offset with strpos() to allow hidden directories
        // before, valid example:
        // /home/foo/.composer/vendor/squiz/custom_tool/MyStandard/Sniffs/...
        if (strpos($path, DIRECTORY_SEPARATOR . '.', $dirLen) !== false) {
            continue;
        }
        if (PHP_CODESNIFFER_VERBOSITY > 1) {
            echo str_repeat("\t", $depth);
            echo "\t\t=> " . Common::stripBasepath($path, $this->config->basepath) . PHP_EOL;
        }
        $sniffs[] = $path;
    }
    
    //end foreach
    return $sniffs;
}
RSS feed
Powered by Drupal