Chris@0
|
1 <?php
|
Chris@0
|
2 /**
|
Chris@0
|
3 * Diff 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 Greg Sherwood <gsherwood@squiz.net>
|
Chris@0
|
10 * @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600)
|
Chris@0
|
11 * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
Chris@0
|
12 * @link http://pear.php.net/package/PHP_CodeSniffer
|
Chris@0
|
13 */
|
Chris@0
|
14
|
Chris@0
|
15 /**
|
Chris@0
|
16 * Diff report for PHP_CodeSniffer.
|
Chris@0
|
17 *
|
Chris@0
|
18 * PHP version 5
|
Chris@0
|
19 *
|
Chris@0
|
20 * @category PHP
|
Chris@0
|
21 * @package PHP_CodeSniffer
|
Chris@0
|
22 * @author Greg Sherwood <gsherwood@squiz.net>
|
Chris@0
|
23 * @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600)
|
Chris@0
|
24 * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
|
Chris@0
|
25 * @version Release: @package_version@
|
Chris@0
|
26 * @link http://pear.php.net/package/PHP_CodeSniffer
|
Chris@0
|
27 */
|
Chris@0
|
28 class PHP_CodeSniffer_Reports_Diff implements PHP_CodeSniffer_Report
|
Chris@0
|
29 {
|
Chris@0
|
30
|
Chris@0
|
31
|
Chris@0
|
32 /**
|
Chris@0
|
33 * Generate a partial report for a single processed file.
|
Chris@0
|
34 *
|
Chris@0
|
35 * Function should return TRUE if it printed or stored data about the file
|
Chris@0
|
36 * and FALSE if it ignored the file. Returning TRUE indicates that the file and
|
Chris@0
|
37 * its data should be counted in the grand totals.
|
Chris@0
|
38 *
|
Chris@0
|
39 * @param array $report Prepared report data.
|
Chris@0
|
40 * @param PHP_CodeSniffer_File $phpcsFile The file being reported on.
|
Chris@0
|
41 * @param boolean $showSources Show sources?
|
Chris@0
|
42 * @param int $width Maximum allowed line width.
|
Chris@0
|
43 *
|
Chris@0
|
44 * @return boolean
|
Chris@0
|
45 */
|
Chris@0
|
46 public function generateFileReport(
|
Chris@0
|
47 $report,
|
Chris@0
|
48 PHP_CodeSniffer_File $phpcsFile,
|
Chris@0
|
49 $showSources=false,
|
Chris@0
|
50 $width=80
|
Chris@0
|
51 ) {
|
Chris@0
|
52 $errors = $phpcsFile->getFixableCount();
|
Chris@0
|
53 if ($errors === 0) {
|
Chris@0
|
54 return false;
|
Chris@0
|
55 }
|
Chris@0
|
56
|
Chris@0
|
57 if (PHP_CODESNIFFER_VERBOSITY > 1) {
|
Chris@0
|
58 ob_end_clean();
|
Chris@0
|
59 echo "\t*** START FILE FIXING ***".PHP_EOL;
|
Chris@0
|
60 }
|
Chris@0
|
61
|
Chris@0
|
62 if (PHP_CODESNIFFER_CBF === true) {
|
Chris@0
|
63 ob_end_clean();
|
Chris@0
|
64 $startTime = microtime(true);
|
Chris@0
|
65 echo "\t=> Fixing file: $errors/$errors violations remaining";
|
Chris@0
|
66 }
|
Chris@0
|
67
|
Chris@0
|
68 $fixed = $phpcsFile->fixer->fixFile();
|
Chris@0
|
69
|
Chris@0
|
70 if (PHP_CODESNIFFER_CBF === true) {
|
Chris@0
|
71 if ($fixed === false) {
|
Chris@0
|
72 echo "\033[31mERROR\033[0m";
|
Chris@0
|
73 } else {
|
Chris@0
|
74 echo "\033[32mDONE\033[0m";
|
Chris@0
|
75 }
|
Chris@0
|
76
|
Chris@0
|
77 $timeTaken = ((microtime(true) - $startTime) * 1000);
|
Chris@0
|
78 if ($timeTaken < 1000) {
|
Chris@0
|
79 $timeTaken = round($timeTaken);
|
Chris@0
|
80 echo " in {$timeTaken}ms".PHP_EOL;
|
Chris@0
|
81 } else {
|
Chris@0
|
82 $timeTaken = round(($timeTaken / 1000), 2);
|
Chris@0
|
83 echo " in $timeTaken secs".PHP_EOL;
|
Chris@0
|
84 }
|
Chris@0
|
85
|
Chris@0
|
86 ob_start();
|
Chris@0
|
87 }
|
Chris@0
|
88
|
Chris@0
|
89 if (PHP_CODESNIFFER_VERBOSITY > 1) {
|
Chris@0
|
90 echo "\t*** END FILE FIXING ***".PHP_EOL;
|
Chris@0
|
91 ob_start();
|
Chris@0
|
92 }
|
Chris@0
|
93
|
Chris@0
|
94 if ($fixed === false) {
|
Chris@0
|
95 return false;
|
Chris@0
|
96 }
|
Chris@0
|
97
|
Chris@0
|
98 if (PHP_CODESNIFFER_CBF === true) {
|
Chris@0
|
99 // Diff without colours.
|
Chris@0
|
100 $diff = $phpcsFile->fixer->generateDiff(null, false);
|
Chris@0
|
101 } else {
|
Chris@0
|
102 $diff = $phpcsFile->fixer->generateDiff();
|
Chris@0
|
103 }
|
Chris@0
|
104
|
Chris@0
|
105 if ($diff === '') {
|
Chris@0
|
106 // Nothing to print.
|
Chris@0
|
107 return false;
|
Chris@0
|
108 }
|
Chris@0
|
109
|
Chris@0
|
110 echo $diff.PHP_EOL;
|
Chris@0
|
111 return true;
|
Chris@0
|
112
|
Chris@0
|
113 }//end generateFileReport()
|
Chris@0
|
114
|
Chris@0
|
115
|
Chris@0
|
116 /**
|
Chris@0
|
117 * Prints all errors and warnings for each file processed.
|
Chris@0
|
118 *
|
Chris@0
|
119 * @param string $cachedData Any partial report data that was returned from
|
Chris@0
|
120 * generateFileReport during the run.
|
Chris@0
|
121 * @param int $totalFiles Total number of files processed during the run.
|
Chris@0
|
122 * @param int $totalErrors Total number of errors found during the run.
|
Chris@0
|
123 * @param int $totalWarnings Total number of warnings found during the run.
|
Chris@0
|
124 * @param int $totalFixable Total number of problems that can be fixed.
|
Chris@0
|
125 * @param boolean $showSources Show sources?
|
Chris@0
|
126 * @param int $width Maximum allowed line width.
|
Chris@0
|
127 * @param boolean $toScreen Is the report being printed to screen?
|
Chris@0
|
128 *
|
Chris@0
|
129 * @return void
|
Chris@0
|
130 */
|
Chris@0
|
131 public function generate(
|
Chris@0
|
132 $cachedData,
|
Chris@0
|
133 $totalFiles,
|
Chris@0
|
134 $totalErrors,
|
Chris@0
|
135 $totalWarnings,
|
Chris@0
|
136 $totalFixable,
|
Chris@0
|
137 $showSources=false,
|
Chris@0
|
138 $width=80,
|
Chris@0
|
139 $toScreen=true
|
Chris@0
|
140 ) {
|
Chris@0
|
141 echo $cachedData;
|
Chris@0
|
142 if ($toScreen === true) {
|
Chris@0
|
143 echo PHP_EOL;
|
Chris@0
|
144 }
|
Chris@0
|
145
|
Chris@0
|
146 }//end generate()
|
Chris@0
|
147
|
Chris@0
|
148
|
Chris@0
|
149 }//end class
|