function Cbf::generateFileReport
Generate a partial report for a single processed file.
Function should return TRUE if it printed or stored data about the file and FALSE if it ignored the file. Returning TRUE indicates that the file and its data should be counted in the grand totals.
Parameters
array<string, string|int|array> $report Prepared report data.: See the {@see Report} interface for a detailed specification.
\PHP_CodeSniffer\Files\File $phpcsFile The file being reported on.:
bool $showSources Show sources?:
int $width Maximum allowed line width.:
Return value
bool
Throws
\PHP_CodeSniffer\Exceptions\DeepExitException
Overrides Report::generateFileReport
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Reports/ Cbf.php, line 40
Class
Namespace
PHP_CodeSniffer\ReportsCode
public function generateFileReport($report, File $phpcsFile, $showSources = false, $width = 80) {
$errors = $phpcsFile->getFixableCount();
if ($errors !== 0) {
if (PHP_CODESNIFFER_VERBOSITY > 0) {
ob_end_clean();
$startTime = microtime(true);
echo "\t=> Fixing file: {$errors}/{$errors} violations remaining";
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo PHP_EOL;
}
}
$fixed = $phpcsFile->fixer
->fixFile();
}
if ($phpcsFile->config->stdin === true) {
// Replacing STDIN, so output current file to STDOUT
// even if nothing was fixed. Exit here because we
// can't process any more than 1 file in this setup.
$fixedContent = $phpcsFile->fixer
->getContents();
throw new DeepExitException($fixedContent, 1);
}
if ($errors === 0) {
return false;
}
if (PHP_CODESNIFFER_VERBOSITY > 0) {
if ($fixed === false) {
echo 'ERROR';
}
else {
echo 'DONE';
}
$timeTaken = (microtime(true) - $startTime) * 1000;
if ($timeTaken < 1000) {
$timeTaken = round($timeTaken);
echo " in {$timeTaken}ms" . PHP_EOL;
}
else {
$timeTaken = round($timeTaken / 1000, 2);
echo " in {$timeTaken} secs" . PHP_EOL;
}
}
if ($fixed === true) {
// The filename in the report may be truncated due to a basepath setting
// but we are using it for writing here and not display,
// so find the correct path if basepath is in use.
$newFilename = $report['filename'] . $phpcsFile->config->suffix;
if ($phpcsFile->config->basepath !== null) {
$newFilename = $phpcsFile->config->basepath . DIRECTORY_SEPARATOR . $newFilename;
}
$newContent = $phpcsFile->fixer
->getContents();
file_put_contents($newFilename, $newContent);
if (PHP_CODESNIFFER_VERBOSITY > 0) {
if ($newFilename === $report['filename']) {
echo "\t=> File was overwritten" . PHP_EOL;
}
else {
echo "\t=> Fixed file written to " . basename($newFilename) . PHP_EOL;
}
}
}
if (PHP_CODESNIFFER_VERBOSITY > 0) {
ob_start();
}
$errorCount = $phpcsFile->getErrorCount();
$warningCount = $phpcsFile->getWarningCount();
$fixableCount = $phpcsFile->getFixableCount();
$fixedCount = $errors - $fixableCount;
echo $report['filename'] . ">>{$errorCount}>>{$warningCount}>>{$fixableCount}>>{$fixedCount}" . PHP_EOL;
return $fixed;
}