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
Namespace
PHP_CodeSnifferCode
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;
}