PHP_CodeSniffer_CLI::printErrorReport PHP Method

printErrorReport() public method

Note that this function may actually print multiple reports as the user may have specified a number of output formats.
public printErrorReport ( PHP_CodeSniffer $phpcs, array $reports, boolean $showSources, string $reportFile, integer $reportWidth ) : integer
$phpcs PHP_CodeSniffer The PHP_CodeSniffer object containing the errors.
$reports array A list of reports to print.
$showSources boolean TRUE if report should show error sources (not used by all reports).
$reportFile string A default file to log report output to.
$reportWidth integer How wide the screen reports should be.
return integer The number of error and warning messages shown.
    public function printErrorReport(PHP_CodeSniffer $phpcs, $reports, $showSources, $reportFile, $reportWidth)
    {
        if (empty($reports) === true) {
            $reports['full'] = $reportFile;
        }
        $errors = 0;
        $warnings = 0;
        $toScreen = false;
        foreach ($reports as $report => $output) {
            if ($output === null) {
                $output = $reportFile;
            }
            if ($reportFile === null) {
                $toScreen = true;
            }
            // We don't add errors here because the number of
            // errors reported by each report type will always be the
            // same, so we really just need 1 number.
            $result = $phpcs->reporting->printReport($report, $showSources, $this->values, $output, $reportWidth);
            $errors = $result['errors'];
            $warnings = $result['warnings'];
        }
        //end foreach
        // Only print timer output if no reports were
        // printed to the screen so we don't put additional output
        // in something like an XML report. If we are printing to screen,
        // the report types would have already worked out who should
        // print the timer info.
        if (PHP_CODESNIFFER_INTERACTIVE === false && ($toScreen === false || $errors + $warnings === 0 && $this->values['showProgress'] === true)) {
            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');
        $return = $errors + $warnings;
        if ($ignoreErrors !== null) {
            $ignoreErrors = (bool) $ignoreErrors;
            if ($ignoreErrors === true) {
                $return -= $errors;
            }
        }
        if ($ignoreWarnings !== null) {
            $ignoreWarnings = (bool) $ignoreWarnings;
            if ($ignoreWarnings === true) {
                $return -= $warnings;
            }
        }
        return $return;
    }