@@ -147,6 +147,53 @@ public function process(PHP_CodeCoverage $coverage, $target)
147147 $ this ->copyFiles ($ target );
148148 }
149149
150+ /**
151+ * @param PHP_CodeCoverage_Report_HTML_Node_Directory $root
152+ * @param array $items
153+ * @param array $files
154+ */
155+ protected function addItems (PHP_CodeCoverage_Report_HTML_Node_Directory $ root , array $ items , array $ files )
156+ {
157+ foreach ($ items as $ key => $ value ) {
158+ if (substr ($ key , -2 ) == '/f ' ) {
159+ try {
160+ $ file = $ root ->addFile (
161+ substr ($ key , 0 , -2 ),
162+ $ value ,
163+ $ this ->options ['yui ' ],
164+ $ this ->options ['highlight ' ]
165+ );
166+ }
167+
168+ catch (RuntimeException $ e ) {
169+ continue ;
170+ }
171+ } else {
172+ $ child = $ root ->addDirectory ($ key );
173+ $ this ->addItems ($ child , $ value , $ files );
174+ }
175+ }
176+ }
177+
178+ /**
179+ * Returns the classes.
180+ *
181+ * @param PHP_CodeCoverage_Report_HTML_Node_Directory $root
182+ * @return array
183+ */
184+ protected function classes (PHP_CodeCoverage_Report_HTML_Node_Directory $ root )
185+ {
186+ $ classes = array ();
187+
188+ foreach ($ root as $ node ) {
189+ $ classes = array_merge ($ classes , $ node ->getClasses ());
190+ }
191+
192+ ksort ($ classes );
193+
194+ return $ classes ;
195+ }
196+
150197 /**
151198 * Renders the Class Coverage Distribution chart.
152199 *
@@ -232,42 +279,26 @@ protected function classCoverageDistributionChart(array $classes, $target)
232279 }
233280
234281 /**
235- * Returns the classes.
236- *
237- * @param PHP_CodeCoverage_Report_HTML_Node_Directory $root
238- * @return array
239- */
240- protected function classes (PHP_CodeCoverage_Report_HTML_Node_Directory $ root )
241- {
242- $ classes = array ();
243-
244- foreach ($ root as $ node ) {
245- $ classes = array_merge ($ classes , $ node ->getClasses ());
246- }
247-
248- ksort ($ classes );
249-
250- return $ classes ;
251- }
252-
253- /**
254- * Returns the top project risks according to the CRAP index.
255- *
256- * @param array $classes
257- * @param integer $max
258- * @return array
282+ * @param string $target
259283 */
260- protected function topProjectRisks ( array $ classes , $ max = 20 )
284+ protected function copyFiles ( $ target )
261285 {
262- $ risks = array ();
286+ $ files = array (
287+ 'butter.png ' ,
288+ 'chameleon.png ' ,
289+ 'close12_1.gif ' ,
290+ 'container.css ' ,
291+ 'container-min.js ' ,
292+ 'glass.png ' ,
293+ 'scarlet_red.png ' ,
294+ 'snow.png ' ,
295+ 'style.css ' ,
296+ 'yahoo-dom-event.js '
297+ );
263298
264- foreach ($ classes as $ className => $ class ) {
265- $ risks [ $ className ] = $ class [ ' crap ' ] ;
299+ foreach ($ files as $ file ) {
300+ copy ( self :: $ templatePath . $ file , $ target . $ file ) ;
266301 }
267-
268- asort ($ risks );
269-
270- return array_reverse (array_slice ($ risks , 0 , max ($ max , count ($ risks ))));
271302 }
272303
273304 /**
@@ -301,53 +332,22 @@ protected function leastTestedMethods(array $classes, $max = 20)
301332 }
302333
303334 /**
304- * @param PHP_CodeCoverage_Report_HTML_Node_Directory $root
305- * @param array $items
306- * @param array $files
335+ * Returns the top project risks according to the CRAP index.
336+ *
337+ * @param array $classes
338+ * @param integer $max
339+ * @return array
307340 */
308- protected function addItems ( PHP_CodeCoverage_Report_HTML_Node_Directory $ root , array $ items , array $ files )
341+ protected function topProjectRisks ( array $ classes , $ max = 20 )
309342 {
310- foreach ($ items as $ key => $ value ) {
311- if (substr ($ key , -2 ) == '/f ' ) {
312- try {
313- $ file = $ root ->addFile (
314- substr ($ key , 0 , -2 ),
315- $ value ,
316- $ this ->options ['yui ' ],
317- $ this ->options ['highlight ' ]
318- );
319- }
343+ $ risks = array ();
320344
321- catch (RuntimeException $ e ) {
322- continue ;
323- }
324- } else {
325- $ child = $ root ->addDirectory ($ key );
326- $ this ->addItems ($ child , $ value , $ files );
327- }
345+ foreach ($ classes as $ className => $ class ) {
346+ $ risks [$ className ] = $ class ['crap ' ];
328347 }
329- }
330348
331- /**
332- * @param string $target
333- */
334- protected function copyFiles ($ target )
335- {
336- $ files = array (
337- 'butter.png ' ,
338- 'chameleon.png ' ,
339- 'close12_1.gif ' ,
340- 'container.css ' ,
341- 'container-min.js ' ,
342- 'glass.png ' ,
343- 'scarlet_red.png ' ,
344- 'snow.png ' ,
345- 'style.css ' ,
346- 'yahoo-dom-event.js '
347- );
349+ asort ($ risks );
348350
349- foreach ($ files as $ file ) {
350- copy (self ::$ templatePath . $ file , $ target . $ file );
351- }
351+ return array_reverse (array_slice ($ risks , 0 , max ($ max , count ($ risks ))));
352352 }
353353}
0 commit comments