3
* Summary report for PHP_CodeSniffer.
8
* @package PHP_CodeSniffer
9
* @author Gabriele Santini <gsantini@sqli.com>
10
* @author Greg Sherwood <gsherwood@squiz.net>
11
* @copyright 2009 SQLI <www.sqli.com>
12
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
13
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
14
* @link http://pear.php.net/package/PHP_CodeSniffer
18
* Summary report for PHP_CodeSniffer.
23
* @package PHP_CodeSniffer
24
* @author Gabriele Santini <gsantini@sqli.com>
25
* @author Greg Sherwood <gsherwood@squiz.net>
26
* @copyright 2009 SQLI <www.sqli.com>
27
* @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
28
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
29
* @version Release: 1.3.4
30
* @link http://pear.php.net/package/PHP_CodeSniffer
32
class PHP_CodeSniffer_Reports_Summary implements PHP_CodeSniffer_Report
37
* Generates a summary of errors and warnings for each file processed.
39
* If verbose output is enabled, results are shown for all files, even if
40
* they have no errors or warnings. If verbose output is disabled, we only
41
* show files that have at least one warning or error.
43
* @param array $report Prepared report.
44
* @param boolean $showSources Show sources?
45
* @param int $width Maximum allowed lne width.
46
* @param boolean $toScreen Is the report being printed to screen?
50
public function generate(
56
$errorFiles = array();
57
$width = max($width, 70);
59
foreach ($report['files'] as $filename => $file) {
60
$numWarnings = $file['warnings'];
61
$numErrors = $file['errors'];
63
// If verbose output is enabled, we show the results for all files,
64
// but if not, we only show files that had errors or warnings.
65
if (PHP_CODESNIFFER_VERBOSITY > 0
69
$errorFiles[$filename] = array(
70
'warnings' => $numWarnings,
71
'errors' => $numErrors,
76
if (empty($errorFiles) === true) {
81
echo PHP_EOL.'PHP CODE SNIFFER REPORT SUMMARY'.PHP_EOL;
82
echo str_repeat('-', $width).PHP_EOL;
83
echo 'FILE'.str_repeat(' ', ($width - 20)).'ERRORS WARNINGS'.PHP_EOL;
84
echo str_repeat('-', $width).PHP_EOL;
90
foreach ($errorFiles as $file => $errors) {
91
$padding = ($width - 18 - strlen($file));
93
$file = '...'.substr($file, (($padding * -1) + 3));
97
echo $file.str_repeat(' ', $padding).' ';
98
echo $errors['errors'];
99
echo str_repeat(' ', (8 - strlen((string) $errors['errors'])));
100
echo $errors['warnings'];
106
echo str_repeat('-', $width).PHP_EOL;
107
echo 'A TOTAL OF '.$report['totals']['errors'].' ERROR(S) ';
108
echo 'AND '.$report['totals']['warnings'].' WARNING(S) ';
110
echo 'WERE FOUND IN '.$totalFiles.' FILE(S)'.PHP_EOL;
111
echo str_repeat('-', $width).PHP_EOL.PHP_EOL;
113
if ($showSources === true) {
114
$source = new PHP_CodeSniffer_Reports_Source();
115
$source->generate($report, $showSources, $width);
118
if ($toScreen === true
119
&& PHP_CODESNIFFER_INTERACTIVE === false
120
&& class_exists('PHP_Timer', false) === true
122
echo PHP_Timer::resourceUsage().PHP_EOL.PHP_EOL;
125
return ($report['totals']['errors'] + $report['totals']['warnings']);