3
* Full 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-2014 SQLI <www.sqli.com>
12
* @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
13
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
14
* @link http://pear.php.net/package/PHP_CodeSniffer
18
* Full 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-2014 SQLI <www.sqli.com>
27
* @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
28
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
29
* @version Release: 1.5.5
30
* @link http://pear.php.net/package/PHP_CodeSniffer
32
class PHP_CodeSniffer_Reports_Full implements PHP_CodeSniffer_Report
37
* Generate a partial report for a single processed file.
39
* Function should return TRUE if it printed or stored data about the file
40
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
41
* its data should be counted in the grand totals.
43
* @param array $report Prepared report data.
44
* @param boolean $showSources Show sources?
45
* @param int $width Maximum allowed line width.
49
public function generateFileReport(
54
if ($report['errors'] === 0 && $report['warnings'] === 0) {
59
$width = max($width, 70);
60
$file = $report['filename'];
62
echo PHP_EOL.'FILE: ';
63
if (strlen($file) <= ($width - 9)) {
66
echo '...'.substr($file, (strlen($file) - ($width - 9)));
70
echo str_repeat('-', $width).PHP_EOL;
72
echo 'FOUND '.$report['errors'].' ERROR(S) ';
73
if ($report['warnings'] > 0) {
74
echo 'AND '.$report['warnings'].' WARNING(S) ';
77
echo 'AFFECTING '.count($report['messages']).' LINE(S)'.PHP_EOL;
78
echo str_repeat('-', $width).PHP_EOL;
80
// Work out the max line number for formatting.
81
$maxLineLength = max(array_map('strlen', array_keys($report['messages'])));
83
// The length of the word ERROR or WARNING; used for padding.
84
if ($report['warnings'] > 0) {
90
// The padding that all lines will require that are
91
// printing an error message overflow.
92
$paddingLine2 = str_repeat(' ', ($maxLineLength + 1));
93
$paddingLine2 .= ' | ';
94
$paddingLine2 .= str_repeat(' ', $typeLength);
95
$paddingLine2 .= ' | ';
97
// The maximum amount of space an error message can use.
98
$maxErrorSpace = ($width - strlen($paddingLine2) - 1);
100
foreach ($report['messages'] as $line => $lineErrors) {
101
foreach ($lineErrors as $column => $colErrors) {
102
foreach ($colErrors as $error) {
103
$message = $error['message'];
104
if ($showSources === true) {
105
$message .= ' ('.$error['source'].')';
108
// The padding that goes on the front of the line.
109
$padding = ($maxLineLength - strlen($line));
110
$errorMsg = wordwrap(
113
PHP_EOL.$paddingLine2
116
echo ' '.str_repeat(' ', $padding).$line.' | '.$error['type'];
117
if ($error['type'] === 'ERROR') {
118
if ($report['warnings'] > 0) {
123
echo ' | '.$errorMsg.PHP_EOL;
128
echo str_repeat('-', $width).PHP_EOL.PHP_EOL;
131
}//end generateFileReport()
135
* Prints all errors and warnings for each file processed.
137
* @param string $cachedData Any partial report data that was returned from
138
* generateFileReport during the run.
139
* @param int $totalFiles Total number of files processed during the run.
140
* @param int $totalErrors Total number of errors found during the run.
141
* @param int $totalWarnings Total number of warnings found during the run.
142
* @param boolean $showSources Show sources?
143
* @param int $width Maximum allowed line width.
144
* @param boolean $toScreen Is the report being printed to screen?
148
public function generate(
157
if ($cachedData === '') {
163
if ($toScreen === true
164
&& PHP_CODESNIFFER_INTERACTIVE === false
165
&& class_exists('PHP_Timer', false) === true
167
echo PHP_Timer::resourceUsage().PHP_EOL.PHP_EOL;