function Runner::processFile
Processes a single file, including checking and fixing.
Parameters
\PHP_CodeSniffer\Files\File $file The file to be processed.:
Return value
void
Throws
\PHP_CodeSniffer\Exceptions\DeepExitException
1 call to Runner::processFile()
- Runner::run in vendor/
squizlabs/ php_codesniffer/ src/ Runner.php - Performs the run.
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Runner.php, line 637
Class
Namespace
PHP_CodeSnifferCode
public function processFile($file) {
if (PHP_CODESNIFFER_VERBOSITY > 0) {
$startTime = microtime(true);
echo 'Processing ' . basename($file->path) . ' ';
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo PHP_EOL;
}
}
try {
$file->process();
if (PHP_CODESNIFFER_VERBOSITY > 0) {
$timeTaken = (microtime(true) - $startTime) * 1000;
if ($timeTaken < 1000) {
$timeTaken = round($timeTaken);
echo "DONE in {$timeTaken}ms";
}
else {
$timeTaken = round($timeTaken / 1000, 2);
echo "DONE in {$timeTaken} secs";
}
if (PHP_CODESNIFFER_CBF === true) {
$errors = $file->getFixableCount();
echo " ({$errors} fixable violations)" . PHP_EOL;
}
else {
$errors = $file->getErrorCount();
$warnings = $file->getWarningCount();
echo " ({$errors} errors, {$warnings} warnings)" . PHP_EOL;
}
}
} catch (Exception $e) {
$error = 'An error occurred during processing; checking has been aborted. The error message was: ' . $e->getMessage();
// Determine which sniff caused the error.
$sniffStack = null;
$nextStack = null;
foreach ($e->getTrace() as $step) {
if (isset($step['file']) === false) {
continue;
}
if (empty($sniffStack) === false) {
$nextStack = $step;
break;
}
if (substr($step['file'], -9) === 'Sniff.php') {
$sniffStack = $step;
continue;
}
}
if (empty($sniffStack) === false) {
$sniffCode = '';
try {
if (empty($nextStack) === false && isset($nextStack['class']) === true && substr($nextStack['class'], -5) === 'Sniff') {
$sniffCode = 'the ' . Common::getSniffCode($nextStack['class']) . ' sniff';
}
} catch (InvalidArgumentException $e) {
// Sniff code could not be determined. This may be an abstract sniff class.
}
if ($sniffCode === '') {
$sniffCode = substr(strrchr(str_replace('\\', '/', $sniffStack['file']), '/'), 1);
}
$error .= sprintf(PHP_EOL . 'The error originated in %s on line %s.', $sniffCode, $sniffStack['line']);
}
$file->addErrorOnLine($error, 1, 'Internal.Exception');
}
//end try
$this->reporter
->cacheFileReport($file);
if ($this->config->interactive === true) {
/*
Running interactively.
Print the error report for the current file and then wait for user input.
*/
// Get current violations and then clear the list to make sure
// we only print violations for a single file each time.
$numErrors = null;
while ($numErrors !== 0) {
$numErrors = $file->getErrorCount() + $file->getWarningCount();
if ($numErrors === 0) {
continue;
}
$this->reporter
->printReport('full');
echo '<ENTER> to recheck, [s] to skip or [q] to quit : ';
$input = fgets(STDIN);
$input = trim($input);
switch ($input) {
case 's':
break 2;
case 'q':
throw new DeepExitException('', 0);
default:
// Repopulate the sniffs because some of them save their state
// and only clear it when the file changes, but we are rechecking
// the same file.
$file->ruleset
->populateTokenListeners();
$file->reloadContent();
$file->process();
$this->reporter
->cacheFileReport($file);
break;
}
}
//end while
}
//end if
// Clean up the file to save (a lot of) memory.
$file->cleanUp();
}