36
36
class PHP_CodeSniffer_Reporting
37
37
{
38
38
39
- private $ _cachedReports = array ();
40
- private $ _reports = array ();
41
-
39
+ /**
40
+ * Total number of files that contain errors or warnings.
41
+ *
42
+ * @var int
43
+ */
42
44
public $ totalFiles = 0 ;
45
+
46
+ /**
47
+ * Total number of errors found during the run.
48
+ *
49
+ * @var int
50
+ */
43
51
public $ totalErrors = 0 ;
52
+
53
+ /**
54
+ * Total number of warnings found during the run.
55
+ *
56
+ * @var int
57
+ */
44
58
public $ totalWarnings = 0 ;
45
59
60
+ /**
61
+ * A list of reports that have written partial report output.
62
+ *
63
+ * @var array
64
+ */
65
+ private $ _cachedReports = array ();
46
66
67
+ /**
68
+ * A cache of report objects.
69
+ *
70
+ * @var array
71
+ */
72
+ private $ _reports = array ();
47
73
48
74
49
75
/**
50
76
* Produce the appropriate report object based on $type parameter.
51
77
*
52
- * @param string $type Demanded report type.
78
+ * @param string $type The type of the report .
53
79
*
54
80
* @return PHP_CodeSniffer_Report
55
81
* @throws PHP_CodeSniffer_Exception If report is not available.
@@ -81,11 +107,59 @@ public function factory($type)
81
107
/**
82
108
* Actually generates the report.
83
109
*
84
- * @param string $report Report type.
85
- * @param array $filesViolations Collected violations.
86
- * @param boolean $showSources Show sources?
87
- * @param string $reportFile Report file to generate.
88
- * @param integer $reportWidth Report max width.
110
+ * @param PHP_CodeSniffer_File $phpcsFile The file that has been processed.
111
+ * @param array $cliValues An array of command line arguments.
112
+ *
113
+ * @return void
114
+ */
115
+ public function cacheFileReport (PHP_CodeSniffer_File $ phpcsFile , array $ cliValues )
116
+ {
117
+ $ reportData = $ this ->prepareFileReport ($ phpcsFile );
118
+ $ errorsShown = false ;
119
+
120
+ foreach ($ cliValues ['reports ' ] as $ report => $ output ) {
121
+ $ reportClass = self ::factory ($ report );
122
+
123
+ ob_start ();
124
+ $ result = $ reportClass ->generateFileReport ($ reportData , $ cliValues ['showSources ' ], $ cliValues ['reportWidth ' ]);
125
+ if ($ result === true ) {
126
+ $ errorsShown = true ;
127
+ }
128
+
129
+ $ generatedReport = ob_get_contents ();
130
+ ob_end_clean ();
131
+
132
+ if ($ generatedReport !== '' ) {
133
+ $ flags = FILE_APPEND ;
134
+ if (in_array ($ report , $ this ->_cachedReports ) === false ) {
135
+ $ this ->_cachedReports [] = $ report ;
136
+ $ flags = null ;
137
+ }
138
+
139
+ if ($ output === null ) {
140
+ $ output = PHPCS_CWD .'/phpcs- ' .$ report .'.tmp ' ;
141
+ }
142
+
143
+ file_put_contents ($ output , $ generatedReport , $ flags );
144
+ }
145
+ }//end foreach
146
+
147
+ if ($ errorsShown === true ) {
148
+ $ this ->totalFiles ++;
149
+ $ this ->totalErrors += $ reportData ['errors ' ];
150
+ $ this ->totalWarnings += $ reportData ['warnings ' ];
151
+ }
152
+
153
+ }//end cacheFileReport()
154
+
155
+
156
+ /**
157
+ * Actually generates the report.
158
+ *
159
+ * @param string $report Report type.
160
+ * @param boolean $showSources Show sources?
161
+ * @param string $reportFile Report file to generate.
162
+ * @param integer $reportWidth Report max width.
89
163
*
90
164
* @return integer
91
165
*/
@@ -117,7 +191,8 @@ public function printReport(
117
191
$ reportCache = '' ;
118
192
}
119
193
120
- $ reportClass ->generate ($ reportCache ,
194
+ $ reportClass ->generate (
195
+ $ reportCache ,
121
196
$ this ->totalFiles ,
122
197
$ this ->totalErrors ,
123
198
$ this ->totalWarnings ,
@@ -128,10 +203,10 @@ public function printReport(
128
203
129
204
if ($ reportFile !== null ) {
130
205
$ generatedReport = ob_get_contents ();
206
+ ob_end_clean ();
207
+
131
208
if (PHP_CODESNIFFER_VERBOSITY > 0 ) {
132
- ob_end_flush ();
133
- } else {
134
- ob_end_clean ();
209
+ echo $ generatedReport ;
135
210
}
136
211
137
212
$ generatedReport = trim ($ generatedReport );
@@ -145,67 +220,12 @@ public function printReport(
145
220
}//end printReport()
146
221
147
222
148
- /**
149
- * Actually generates the report.
150
- *
151
- * @param string $report Report type.
152
- * @param array $filesViolations Collected violations.
153
- * @param boolean $showSources Show sources?
154
- * @param string $reportFile Report file to generate.
155
- * @param integer $reportWidth Report max width.
156
- *
157
- * @return integer
158
- */
159
- public function cacheFileReport (
160
- PHP_CodeSniffer_File $ phpcsFile ,
161
- array $ cliValues
162
- ) {
163
-
164
- $ reportData = $ this ->prepareFileReport ($ phpcsFile );
165
- $ errorsShown = false ;
166
-
167
- foreach ($ cliValues ['reports ' ] as $ report => $ output ) {
168
- $ reportClass = self ::factory ($ report );
169
-
170
- ob_start ();
171
- $ result = $ reportClass ->generateFileReport ($ reportData , $ cliValues ['showSources ' ], $ cliValues ['reportWidth ' ]);
172
- if ($ result === true ) {
173
- $ errorsShown = true ;
174
- }
175
-
176
- $ generatedReport = ob_get_contents ();
177
- ob_end_clean ();
178
-
179
- if ($ generatedReport !== '' ) {
180
- $ flags = FILE_APPEND ;
181
- if (in_array ($ report , $ this ->_cachedReports ) === false ) {
182
- $ this ->_cachedReports [] = $ report ;
183
- $ flags = null ;
184
- }
185
-
186
- if ($ output === null ) {
187
- $ output = PHPCS_CWD .'/phpcs- ' .$ report .'.tmp ' ;
188
- }
189
-
190
- file_put_contents ($ output , $ generatedReport , $ flags );
191
- }
192
- }//end foreach
193
-
194
- if ($ errorsShown === true ) {
195
- $ this ->totalFiles ++;
196
- $ this ->totalErrors += $ reportData ['errors ' ];
197
- $ this ->totalWarnings += $ reportData ['warnings ' ];
198
- }
199
-
200
- }//end printReport()
201
-
202
-
203
223
/**
204
224
* Pre-process and package violations for all files.
205
225
*
206
226
* Used by error reports to get a packaged list of all errors in each file.
207
227
*
208
- * @param array $filesViolations List of found violations .
228
+ * @param PHP_CodeSniffer_File $phpcsFile The file that has been processed .
209
229
*
210
230
* @return array
211
231
*/
@@ -277,7 +297,7 @@ public function prepareFileReport(PHP_CodeSniffer_File $phpcsFile)
277
297
$ report ['messages ' ] = $ errors ;
278
298
return $ report ;
279
299
280
- }//end prepare ()
300
+ }//end prepareFileReport ()
281
301
282
302
283
303
}//end class
0 commit comments