function Runner::runPHPCBF
Run the PHPCBF script.
Return value
int
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Runner.php, line 160
Class
Namespace
PHP_CodeSnifferCode
public function runPHPCBF() {
$this->registerOutOfMemoryShutdownMessage('phpcbf');
if (defined('PHP_CODESNIFFER_CBF') === false) {
define('PHP_CODESNIFFER_CBF', true);
}
try {
Timing::startTiming();
Runner::checkRequirements();
// Creating the Config object populates it with all required settings
// based on the CLI arguments provided to the script and any config
// values the user has set.
$this->config = new Config();
// When processing STDIN, we can't output anything to the screen
// or it will end up mixed in with the file output.
if ($this->config->stdin === true) {
$this->config->verbosity = 0;
}
// Init the run and load the rulesets to set additional config vars.
$this->init();
// When processing STDIN, we only process one file at a time and
// we don't process all the way through, so we can't use the parallel
// running system.
if ($this->config->stdin === true) {
$this->config->parallel = 1;
}
// Override some of the command line settings that might break the fixes.
$this->config->generator = null;
$this->config->explain = false;
$this->config->interactive = false;
$this->config->cache = false;
$this->config->showSources = false;
$this->config->recordErrors = false;
$this->config->reportFile = null;
// Only use the "Cbf" report, but allow for the Performance report as well.
$originalReports = array_change_key_case($this->config->reports, CASE_LOWER);
$newReports = [
'cbf' => null,
];
if (array_key_exists('performance', $originalReports) === true) {
$newReports['performance'] = $originalReports['performance'];
}
$this->config->reports = $newReports;
// If a standard tries to set command line arguments itself, some
// may be blocked because PHPCBF is running, so stop the script
// dying if any are found.
$this->config->dieOnUnknownArg = false;
$this->run();
$this->reporter
->printReports();
echo PHP_EOL;
Timing::printRunTime();
} catch (DeepExitException $e) {
echo $e->getMessage();
return $e->getCode();
}
//end try
if ($this->reporter->totalFixed === 0) {
// Nothing was fixed by PHPCBF.
if ($this->reporter->totalFixable === 0) {
// Nothing found that could be fixed.
return 0;
}
else {
// Something failed to fix.
return 2;
}
}
if ($this->reporter->totalFixable === 0) {
// PHPCBF fixed all fixable errors.
return 1;
}
// PHPCBF fixed some fixable errors, but others failed to fix.
return 2;
}