public function registerSniffs($files, $restrictions, $exclusions)
{
$listeners = array();
foreach ($files as $file) {
// Work out where the position of /StandardName/Sniffs/... is
// so we can determine what the class will be called.
$sniffPos = strrpos($file, DIRECTORY_SEPARATOR . 'Sniffs' . DIRECTORY_SEPARATOR);
if ($sniffPos === false) {
continue;
}
$slashPos = strrpos(substr($file, 0, $sniffPos), DIRECTORY_SEPARATOR);
if ($slashPos === false) {
continue;
}
$className = substr($file, $slashPos + 1);
if (substr_count($className, DIRECTORY_SEPARATOR) !== 3) {
throw new PHP_CodeSniffer_Exception("Sniff file {$className} is not valid; sniff files must be located in a .../StandardName/Sniffs/CategoryName/ directory");
}
$className = substr($className, 0, -4);
$className = str_replace(DIRECTORY_SEPARATOR, '_', $className);
// If they have specified a list of sniffs to restrict to, check
// to see if this sniff is allowed.
if (empty($restrictions) === false && in_array(strtolower($className), $restrictions) === false) {
continue;
}
// If they have specified a list of sniffs to exclude, check
// to see if this sniff is allowed.
if (empty($exclusions) === false && in_array(strtolower($className), $exclusions) === true) {
continue;
}
include_once $file;
// Support the use of PHP namespaces. If the class name we included
// contains namespace separators instead of underscores, use this as the
// class name from now on.
$classNameNS = str_replace('_', '\\', $className);
if (class_exists($classNameNS, false) === true) {
$className = $classNameNS;
}
// Skip abstract classes.
$reflection = new ReflectionClass($className);
if ($reflection->isAbstract() === true) {
continue;
}
$listeners[$className] = $className;
if (PHP_CODESNIFFER_VERBOSITY > 2) {
echo "Registered {$className}" . PHP_EOL;
}
}
//end foreach
$this->sniffs = $listeners;
}