Skip to content

Commit

Permalink
Refactor part of printErrorReport into method
Browse files Browse the repository at this point in the history
This reduces the N path complexity of the printErrorReport method and improves the readability.
  • Loading branch information
ravage84 committed May 19, 2015
1 parent 9de93e0 commit e0f3f4f
Showing 1 changed file with 57 additions and 9 deletions.
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

0 comments on commit e0f3f4f

Please sign in to comment.