Mercurial > hg > cmmr2012-drupal-site
comparison vendor/squizlabs/php_codesniffer/src/Reports/Summary.php @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3:307d7a7fd348 | 4:a9cd425dd02b |
---|---|
1 <?php | |
2 /** | |
3 * Summary report for PHP_CodeSniffer. | |
4 * | |
5 * @author Greg Sherwood <gsherwood@squiz.net> | |
6 * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600) | |
7 * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence | |
8 */ | |
9 | |
10 namespace PHP_CodeSniffer\Reports; | |
11 | |
12 use PHP_CodeSniffer\Files\File; | |
13 use PHP_CodeSniffer\Util; | |
14 | |
15 class Summary implements Report | |
16 { | |
17 | |
18 | |
19 /** | |
20 * Generate a partial report for a single processed file. | |
21 * | |
22 * Function should return TRUE if it printed or stored data about the file | |
23 * and FALSE if it ignored the file. Returning TRUE indicates that the file and | |
24 * its data should be counted in the grand totals. | |
25 * | |
26 * @param array $report Prepared report data. | |
27 * @param \PHP_CodeSniffer\File $phpcsFile The file being reported on. | |
28 * @param bool $showSources Show sources? | |
29 * @param int $width Maximum allowed line width. | |
30 * | |
31 * @return bool | |
32 */ | |
33 public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80) | |
34 { | |
35 if (PHP_CODESNIFFER_VERBOSITY === 0 | |
36 && $report['errors'] === 0 | |
37 && $report['warnings'] === 0 | |
38 ) { | |
39 // Nothing to print. | |
40 return false; | |
41 } | |
42 | |
43 echo $report['filename'].'>>'.$report['errors'].'>>'.$report['warnings'].PHP_EOL; | |
44 return true; | |
45 | |
46 }//end generateFileReport() | |
47 | |
48 | |
49 /** | |
50 * Generates a summary of errors and warnings for each file processed. | |
51 * | |
52 * @param string $cachedData Any partial report data that was returned from | |
53 * generateFileReport during the run. | |
54 * @param int $totalFiles Total number of files processed during the run. | |
55 * @param int $totalErrors Total number of errors found during the run. | |
56 * @param int $totalWarnings Total number of warnings found during the run. | |
57 * @param int $totalFixable Total number of problems that can be fixed. | |
58 * @param bool $showSources Show sources? | |
59 * @param int $width Maximum allowed line width. | |
60 * @param bool $interactive Are we running in interactive mode? | |
61 * @param bool $toScreen Is the report being printed to screen? | |
62 * | |
63 * @return void | |
64 */ | |
65 public function generate( | |
66 $cachedData, | |
67 $totalFiles, | |
68 $totalErrors, | |
69 $totalWarnings, | |
70 $totalFixable, | |
71 $showSources=false, | |
72 $width=80, | |
73 $interactive=false, | |
74 $toScreen=true | |
75 ) { | |
76 $lines = explode(PHP_EOL, $cachedData); | |
77 array_pop($lines); | |
78 | |
79 if (empty($lines) === true) { | |
80 return; | |
81 } | |
82 | |
83 $reportFiles = []; | |
84 $maxLength = 0; | |
85 | |
86 foreach ($lines as $line) { | |
87 $parts = explode('>>', $line); | |
88 $fileLen = strlen($parts[0]); | |
89 $reportFiles[$parts[0]] = [ | |
90 'errors' => $parts[1], | |
91 'warnings' => $parts[2], | |
92 'strlen' => $fileLen, | |
93 ]; | |
94 | |
95 $maxLength = max($maxLength, $fileLen); | |
96 } | |
97 | |
98 uksort( | |
99 $reportFiles, | |
100 function ($keyA, $keyB) { | |
101 $pathPartsA = explode(DIRECTORY_SEPARATOR, $keyA); | |
102 $pathPartsB = explode(DIRECTORY_SEPARATOR, $keyB); | |
103 | |
104 do { | |
105 $partA = array_shift($pathPartsA); | |
106 $partB = array_shift($pathPartsB); | |
107 } while ($partA === $partB && empty($pathPartsA) === false && empty($pathPartsB) === false); | |
108 | |
109 if (empty($pathPartsA) === false && empty($pathPartsB) === true) { | |
110 return 1; | |
111 } else if (empty($pathPartsA) === true && empty($pathPartsB) === false) { | |
112 return -1; | |
113 } else { | |
114 return strcasecmp($partA, $partB); | |
115 } | |
116 } | |
117 ); | |
118 | |
119 $width = min($width, ($maxLength + 21)); | |
120 $width = max($width, 70); | |
121 | |
122 echo PHP_EOL."\033[1m".'PHP CODE SNIFFER REPORT SUMMARY'."\033[0m".PHP_EOL; | |
123 echo str_repeat('-', $width).PHP_EOL; | |
124 echo "\033[1m".'FILE'.str_repeat(' ', ($width - 20)).'ERRORS WARNINGS'."\033[0m".PHP_EOL; | |
125 echo str_repeat('-', $width).PHP_EOL; | |
126 | |
127 foreach ($reportFiles as $file => $data) { | |
128 $padding = ($width - 18 - $data['strlen']); | |
129 if ($padding < 0) { | |
130 $file = '...'.substr($file, (($padding * -1) + 3)); | |
131 $padding = 0; | |
132 } | |
133 | |
134 echo $file.str_repeat(' ', $padding).' '; | |
135 if ($data['errors'] !== 0) { | |
136 echo "\033[31m".$data['errors']."\033[0m"; | |
137 echo str_repeat(' ', (8 - strlen((string) $data['errors']))); | |
138 } else { | |
139 echo '0 '; | |
140 } | |
141 | |
142 if ($data['warnings'] !== 0) { | |
143 echo "\033[33m".$data['warnings']."\033[0m"; | |
144 } else { | |
145 echo '0'; | |
146 } | |
147 | |
148 echo PHP_EOL; | |
149 }//end foreach | |
150 | |
151 echo str_repeat('-', $width).PHP_EOL; | |
152 echo "\033[1mA TOTAL OF $totalErrors ERROR"; | |
153 if ($totalErrors !== 1) { | |
154 echo 'S'; | |
155 } | |
156 | |
157 echo ' AND '.$totalWarnings.' WARNING'; | |
158 if ($totalWarnings !== 1) { | |
159 echo 'S'; | |
160 } | |
161 | |
162 echo ' WERE FOUND IN '.$totalFiles.' FILE'; | |
163 if ($totalFiles !== 1) { | |
164 echo 'S'; | |
165 } | |
166 | |
167 echo "\033[0m"; | |
168 | |
169 if ($totalFixable > 0) { | |
170 echo PHP_EOL.str_repeat('-', $width).PHP_EOL; | |
171 echo "\033[1mPHPCBF CAN FIX $totalFixable OF THESE SNIFF VIOLATIONS AUTOMATICALLY\033[0m"; | |
172 } | |
173 | |
174 echo PHP_EOL.str_repeat('-', $width).PHP_EOL.PHP_EOL; | |
175 | |
176 if ($toScreen === true && $interactive === false) { | |
177 Util\Timing::printRunTime(); | |
178 } | |
179 | |
180 }//end generate() | |
181 | |
182 | |
183 }//end class |