Chris@0
|
1 <?php
|
Chris@0
|
2 /**
|
Chris@0
|
3 * Summary report for PHP_CodeSniffer.
|
Chris@0
|
4 *
|
Chris@0
|
5 * PHP version 5
|
Chris@0
|
6 *
|
Chris@0
|
7 * @category PHP
|
Chris@0
|
8 * @package PHP_CodeSniffer
|
Chris@0
|
9 * @author Gabriele Santini <gsantini@sqli.com>
|
Chris@0
|
10 * @author Greg Sherwood <gsherwood@squiz.net>
|
Chris@0
|
11 * @copyright 2009-2014 SQLI <www.sqli.com>
|
Chris@0
|
12 * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
|
Chris@0
|
13 * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
Chris@0
|
14 * @link http://pear.php.net/package/PHP_CodeSniffer
|
Chris@0
|
15 */
|
Chris@0
|
16
|
Chris@0
|
17 /**
|
Chris@0
|
18 * Summary report for PHP_CodeSniffer.
|
Chris@0
|
19 *
|
Chris@0
|
20 * PHP version 5
|
Chris@0
|
21 *
|
Chris@0
|
22 * @category PHP
|
Chris@0
|
23 * @package PHP_CodeSniffer
|
Chris@0
|
24 * @author Gabriele Santini <gsantini@sqli.com>
|
Chris@0
|
25 * @author Greg Sherwood <gsherwood@squiz.net>
|
Chris@0
|
26 * @copyright 2009-2014 SQLI <www.sqli.com>
|
Chris@0
|
27 * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
|
Chris@0
|
28 * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
Chris@0
|
29 * @version Release: @package_version@
|
Chris@0
|
30 * @link http://pear.php.net/package/PHP_CodeSniffer
|
Chris@0
|
31 */
|
Chris@0
|
32 class PHP_CodeSniffer_Reports_Summary implements PHP_CodeSniffer_Report
|
Chris@0
|
33 {
|
Chris@0
|
34
|
Chris@0
|
35 /**
|
Chris@0
|
36 * TRUE if this report needs error messages instead of just totals.
|
Chris@0
|
37 *
|
Chris@0
|
38 * @var boolean
|
Chris@0
|
39 */
|
Chris@0
|
40 public $recordErrors = false;
|
Chris@0
|
41
|
Chris@0
|
42 /**
|
Chris@0
|
43 * An array of process files and their error data.
|
Chris@0
|
44 *
|
Chris@0
|
45 * @var boolean
|
Chris@0
|
46 */
|
Chris@0
|
47 private $_reportFiles = array();
|
Chris@0
|
48
|
Chris@0
|
49
|
Chris@0
|
50 /**
|
Chris@0
|
51 * Generate a partial report for a single processed file.
|
Chris@0
|
52 *
|
Chris@0
|
53 * Function should return TRUE if it printed or stored data about the file
|
Chris@0
|
54 * and FALSE if it ignored the file. Returning TRUE indicates that the file and
|
Chris@0
|
55 * its data should be counted in the grand totals.
|
Chris@0
|
56 *
|
Chris@0
|
57 * @param array $report Prepared report data.
|
Chris@0
|
58 * @param PHP_CodeSniffer_File $phpcsFile The file being reported on.
|
Chris@0
|
59 * @param boolean $showSources Show sources?
|
Chris@0
|
60 * @param int $width Maximum allowed line width.
|
Chris@0
|
61 *
|
Chris@0
|
62 * @return boolean
|
Chris@0
|
63 */
|
Chris@0
|
64 public function generateFileReport(
|
Chris@0
|
65 $report,
|
Chris@0
|
66 PHP_CodeSniffer_File $phpcsFile,
|
Chris@0
|
67 $showSources=false,
|
Chris@0
|
68 $width=80
|
Chris@0
|
69 ) {
|
Chris@0
|
70 if (PHP_CODESNIFFER_VERBOSITY === 0
|
Chris@0
|
71 && $report['errors'] === 0
|
Chris@0
|
72 && $report['warnings'] === 0
|
Chris@0
|
73 ) {
|
Chris@0
|
74 // Nothing to print.
|
Chris@0
|
75 return false;
|
Chris@0
|
76 }
|
Chris@0
|
77
|
Chris@0
|
78 $this->_reportFiles[$report['filename']] = array(
|
Chris@0
|
79 'errors' => $report['errors'],
|
Chris@0
|
80 'warnings' => $report['warnings'],
|
Chris@0
|
81 'strlen' => strlen($report['filename']),
|
Chris@0
|
82 );
|
Chris@0
|
83
|
Chris@0
|
84 return true;
|
Chris@0
|
85
|
Chris@0
|
86 }//end generateFileReport()
|
Chris@0
|
87
|
Chris@0
|
88
|
Chris@0
|
89 /**
|
Chris@0
|
90 * Generates a summary of errors and warnings for each file processed.
|
Chris@0
|
91 *
|
Chris@0
|
92 * @param string $cachedData Any partial report data that was returned from
|
Chris@0
|
93 * generateFileReport during the run.
|
Chris@0
|
94 * @param int $totalFiles Total number of files processed during the run.
|
Chris@0
|
95 * @param int $totalErrors Total number of errors found during the run.
|
Chris@0
|
96 * @param int $totalWarnings Total number of warnings found during the run.
|
Chris@0
|
97 * @param int $totalFixable Total number of problems that can be fixed.
|
Chris@0
|
98 * @param boolean $showSources Show sources?
|
Chris@0
|
99 * @param int $width Maximum allowed line width.
|
Chris@0
|
100 * @param boolean $toScreen Is the report being printed to screen?
|
Chris@0
|
101 *
|
Chris@0
|
102 * @return void
|
Chris@0
|
103 */
|
Chris@0
|
104 public function generate(
|
Chris@0
|
105 $cachedData,
|
Chris@0
|
106 $totalFiles,
|
Chris@0
|
107 $totalErrors,
|
Chris@0
|
108 $totalWarnings,
|
Chris@0
|
109 $totalFixable,
|
Chris@0
|
110 $showSources=false,
|
Chris@0
|
111 $width=80,
|
Chris@0
|
112 $toScreen=true
|
Chris@0
|
113 ) {
|
Chris@0
|
114
|
Chris@0
|
115 if (empty($this->_reportFiles) === true) {
|
Chris@0
|
116 return;
|
Chris@0
|
117 }
|
Chris@0
|
118
|
Chris@0
|
119 // Make sure the report width isn't too big.
|
Chris@0
|
120 $maxLength = 0;
|
Chris@0
|
121 foreach ($this->_reportFiles as $file => $data) {
|
Chris@0
|
122 $maxLength = max($maxLength, $data['strlen']);
|
Chris@0
|
123 }
|
Chris@0
|
124
|
Chris@0
|
125 $width = min($width, ($maxLength + 21));
|
Chris@0
|
126 $width = max($width, 70);
|
Chris@0
|
127
|
Chris@0
|
128 echo PHP_EOL."\033[1m".'PHP CODE SNIFFER REPORT SUMMARY'."\033[0m".PHP_EOL;
|
Chris@0
|
129 echo str_repeat('-', $width).PHP_EOL;
|
Chris@0
|
130 echo "\033[1m".'FILE'.str_repeat(' ', ($width - 20)).'ERRORS WARNINGS'."\033[0m".PHP_EOL;
|
Chris@0
|
131 echo str_repeat('-', $width).PHP_EOL;
|
Chris@0
|
132
|
Chris@0
|
133 foreach ($this->_reportFiles as $file => $data) {
|
Chris@0
|
134 $padding = ($width - 18 - $data['strlen']);
|
Chris@0
|
135 if ($padding < 0) {
|
Chris@0
|
136 $file = '...'.substr($file, (($padding * -1) + 3));
|
Chris@0
|
137 $padding = 0;
|
Chris@0
|
138 }
|
Chris@0
|
139
|
Chris@0
|
140 echo $file.str_repeat(' ', $padding).' ';
|
Chris@0
|
141 if ($data['errors'] !== 0) {
|
Chris@0
|
142 echo "\033[31m".$data['errors']."\033[0m";
|
Chris@0
|
143 echo str_repeat(' ', (8 - strlen((string) $data['errors'])));
|
Chris@0
|
144 } else {
|
Chris@0
|
145 echo '0 ';
|
Chris@0
|
146 }
|
Chris@0
|
147
|
Chris@0
|
148 if ($data['warnings'] !== 0) {
|
Chris@0
|
149 echo "\033[33m".$data['warnings']."\033[0m";
|
Chris@0
|
150 } else {
|
Chris@0
|
151 echo '0';
|
Chris@0
|
152 }
|
Chris@0
|
153
|
Chris@0
|
154 echo PHP_EOL;
|
Chris@0
|
155 }//end foreach
|
Chris@0
|
156
|
Chris@0
|
157 echo str_repeat('-', $width).PHP_EOL;
|
Chris@0
|
158 echo "\033[1mA TOTAL OF $totalErrors ERROR";
|
Chris@0
|
159 if ($totalErrors !== 1) {
|
Chris@0
|
160 echo 'S';
|
Chris@0
|
161 }
|
Chris@0
|
162
|
Chris@0
|
163 echo ' AND '.$totalWarnings.' WARNING';
|
Chris@0
|
164 if ($totalWarnings !== 1) {
|
Chris@0
|
165 echo 'S';
|
Chris@0
|
166 }
|
Chris@0
|
167
|
Chris@0
|
168 echo ' WERE FOUND IN '.$totalFiles.' FILE';
|
Chris@0
|
169 if ($totalFiles !== 1) {
|
Chris@0
|
170 echo 'S';
|
Chris@0
|
171 }
|
Chris@0
|
172
|
Chris@0
|
173 echo "\033[0m";
|
Chris@0
|
174
|
Chris@0
|
175 if ($totalFixable > 0) {
|
Chris@0
|
176 echo PHP_EOL.str_repeat('-', $width).PHP_EOL;
|
Chris@0
|
177 echo "\033[1mPHPCBF CAN FIX $totalFixable OF THESE SNIFF VIOLATIONS AUTOMATICALLY\033[0m";
|
Chris@0
|
178 }
|
Chris@0
|
179
|
Chris@0
|
180 echo PHP_EOL.str_repeat('-', $width).PHP_EOL.PHP_EOL;
|
Chris@0
|
181
|
Chris@0
|
182 if ($toScreen === true && PHP_CODESNIFFER_INTERACTIVE === false) {
|
Chris@0
|
183 PHP_CodeSniffer_Reporting::printRunTime();
|
Chris@0
|
184 }
|
Chris@0
|
185
|
Chris@0
|
186 }//end generate()
|
Chris@0
|
187
|
Chris@0
|
188
|
Chris@0
|
189 }//end class
|