Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor part of printErrorReport into method #597

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
66 changes: 57 additions & 9 deletions CodeSniffer/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -969,29 +969,77 @@ public function printErrorReport(
PHP_CodeSniffer_Reporting::printRunTime();
}

// They should all return the same value, so it
// doesn't matter which return value we end up using.
$ignoreWarnings = PHP_CodeSniffer::getConfigData('ignore_warnings_on_exit');
$ignoreErrors = PHP_CodeSniffer::getConfigData('ignore_errors_on_exit');
// All calls to printReport() should return the same value,
// so it doesn't matter which return value we end up using.
return $this->calculateErrorsAndWarnings($errors, $warnings);

}//end printErrorReport()


$return = ($errors + $warnings);
/**
* Calculate how many errors and warnings should be shown
*
* @param int $errors The number of errors.
* @param int $warnings The number of warnings.
*
* @return int The number of error and warning messages to be shown.
*/
protected function calculateErrorsAndWarnings($errors, $warnings)
{
$errorsAndWarnings = ($errors + $warnings);

$errorsAndWarnings = $this->ignoreErrors($errors, $errorsAndWarnings);
$errorsAndWarnings = $this->ignoreWarnings($warnings, $errorsAndWarnings);

return $errorsAndWarnings;

}//end calculateErrorsAndWarnings()


/**
* If configured, ignore errors
*
* @param int $errors The number of errors.
* @param int $errorsAndWarnings The accumulated number of errors and warnings.
*
* @return int The number of error and warning messages to be shown.
*/
protected function ignoreErrors($errors, $errorsAndWarnings)
{
$ignoreErrors = PHP_CodeSniffer::getConfigData('ignore_errors_on_exit');
if ($ignoreErrors !== null) {
$ignoreErrors = (bool) $ignoreErrors;
if ($ignoreErrors === true) {
$return -= $errors;
$errorsAndWarnings -= $errors;
}
}

return $errorsAndWarnings;

}//end ignoreErrors()


/**
* If configured, ignore warnings
*
* @param int $warnings The number of warnings.
* @param int $errorsAndWarnings The accumulated number of errors and warnings.
*
* @return int The number of error and warning messages to be shown.
*/
protected function ignoreWarnings($warnings, $errorsAndWarnings)
{
$ignoreWarnings = PHP_CodeSniffer::getConfigData('ignore_warnings_on_exit');
if ($ignoreWarnings !== null) {
$ignoreWarnings = (bool) $ignoreWarnings;
if ($ignoreWarnings === true) {
$return -= $warnings;
$errorsAndWarnings -= $warnings;
}
}

return $return;
return $errorsAndWarnings;

}//end printErrorReport()
}//end ignoreWarnings()


/**
Expand Down