function Ruleset::explain
Prints a report showing the sniffs contained in a standard.
Return value
void
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Ruleset.php, line 253
Class
Namespace
PHP_CodeSnifferCode
public function explain() {
$sniffs = array_keys($this->sniffCodes);
sort($sniffs, SORT_NATURAL | SORT_FLAG_CASE);
$sniffCount = count($sniffs);
// Add a dummy entry to the end so we loop one last time
// and echo out the collected info about the last standard.
$sniffs[] = '';
$summaryLine = PHP_EOL . "The {$this->name} standard contains 1 sniff" . PHP_EOL;
if ($sniffCount !== 1) {
$summaryLine = str_replace('1 sniff', "{$sniffCount} sniffs", $summaryLine);
}
echo $summaryLine;
$lastStandard = null;
$lastCount = 0;
$sniffsInStandard = [];
foreach ($sniffs as $i => $sniff) {
if ($i === $sniffCount) {
$currentStandard = null;
}
else {
$currentStandard = substr($sniff, 0, strpos($sniff, '.'));
if ($lastStandard === null) {
$lastStandard = $currentStandard;
}
}
// Reached the first item in the next standard.
// Echo out the info collected from the previous standard.
if ($currentStandard !== $lastStandard) {
$subTitle = $lastStandard . ' (' . $lastCount . ' sniff';
if ($lastCount > 1) {
$subTitle .= 's';
}
$subTitle .= ')';
echo PHP_EOL . $subTitle . PHP_EOL;
echo str_repeat('-', strlen($subTitle)) . PHP_EOL;
echo ' ' . implode(PHP_EOL . ' ', $sniffsInStandard) . PHP_EOL;
$lastStandard = $currentStandard;
$lastCount = 0;
$sniffsInStandard = [];
if ($currentStandard === null) {
break;
}
}
//end if
if (isset($this->deprecatedSniffs[$sniff]) === true) {
$sniff .= ' *';
}
$sniffsInStandard[] = $sniff;
++$lastCount;
}
//end foreach
if (count($this->deprecatedSniffs) > 0) {
echo PHP_EOL . '* Sniffs marked with an asterix are deprecated.' . PHP_EOL;
}
}