@@ -62,17 +62,19 @@ class PHP_CodeCoverage_Report_HTML_Renderer_Dashboard extends PHP_CodeCoverage_R
6262 */
6363 public function render (PHP_CodeCoverage_Report_Node_Directory $ node , $ file )
6464 {
65- $ classes = $ node ->getClassesAndTraits ();
65+ $ classes = $ node ->getClassesAndTraits ();
66+ $ isRoot = $ node ->getParent () === null ;
67+
6668 $ template = new Text_Template (
6769 $ this ->templatePath . 'dashboard.html ' , '{{ ' , '}} '
6870 );
6971
7072 $ this ->setCommonTemplateVariables ($ template , $ node );
7173
72- $ complexity = $ this ->complexity ($ classes );
73- $ coverageDistribution = $ this ->coverageDistribution ($ classes );
74- $ insufficientCoverage = $ this ->insufficientCoverage ($ classes );
75- $ projectRisks = $ this ->projectRisks ($ classes );
74+ $ complexity = $ this ->complexity ($ classes, $ isRoot );
75+ $ coverageDistribution = $ this ->coverageDistribution ($ classes, $ isRoot );
76+ $ insufficientCoverage = $ this ->insufficientCoverage ($ classes, $ isRoot );
77+ $ projectRisks = $ this ->projectRisks ($ classes, $ isRoot );
7678
7779 $ template ->setVar (
7880 array (
@@ -93,10 +95,11 @@ public function render(PHP_CodeCoverage_Report_Node_Directory $node, $file)
9395 /**
9496 * Returns the data for the Class/Method Complexity charts.
9597 *
96- * @param array $classes
98+ * @param array $classes
99+ * @param boolean $isRoot
97100 * @return array
98101 */
99- protected function complexity (array $ classes )
102+ protected function complexity (array $ classes, $ isRoot )
100103 {
101104 $ result = array ('class ' => array (), 'method ' => array ());
102105
@@ -111,7 +114,7 @@ protected function complexity(array $classes)
111114 $ method ['ccn ' ],
112115 sprintf (
113116 '<a href="%s">%s</a> ' ,
114- $ method ['link ' ],
117+ $ this -> rebaseLink ( $ method ['link ' ], $ isRoot ) ,
115118 $ methodName
116119 )
117120 );
@@ -122,7 +125,7 @@ protected function complexity(array $classes)
122125 $ class ['ccn ' ],
123126 sprintf (
124127 '<a href="%s">%s</a> ' ,
125- $ class ['link ' ],
128+ $ this -> rebaseLink ( $ class ['link ' ], $ isRoot ) ,
126129 $ className
127130 )
128131 );
@@ -137,10 +140,11 @@ protected function complexity(array $classes)
137140 /**
138141 * Returns the data for the Class / Method Coverage Distribution chart.
139142 *
140- * @param array $classes
143+ * @param array $classes
144+ * @param boolean $isRoot
141145 * @return array
142146 */
143- protected function coverageDistribution (array $ classes )
147+ protected function coverageDistribution (array $ classes, $ isRoot )
144148 {
145149 $ result = array (
146150 'class ' => array (
@@ -206,10 +210,11 @@ protected function coverageDistribution(array $classes)
206210 /**
207211 * Returns the classes / methods with insufficient coverage.
208212 *
209- * @param array $classes
213+ * @param array $classes
214+ * @param boolean $isRoot
210215 * @return array
211216 */
212- protected function insufficientCoverage (array $ classes )
217+ protected function insufficientCoverage (array $ classes, $ isRoot )
213218 {
214219 $ leastTestedClasses = array ();
215220 $ leastTestedMethods = array ();
@@ -239,7 +244,7 @@ protected function insufficientCoverage(array $classes)
239244 foreach ($ leastTestedClasses as $ className => $ coverage ) {
240245 $ result ['class ' ] .= sprintf (
241246 ' <tr><td><a href="%s">%s</a></td><td class="text-right">%d%%</td></tr> ' . "\n" ,
242- $ classes [$ className ]['link ' ],
247+ $ this -> rebaseLink ( $ classes [$ className ]['link ' ], $ isRoot ) ,
243248 $ className ,
244249 $ coverage
245250 );
@@ -250,7 +255,7 @@ protected function insufficientCoverage(array $classes)
250255
251256 $ result ['method ' ] .= sprintf (
252257 ' <tr><td><a href="%s"><abbr title="%s">%s</a></a></td><td class="text-right">%d%%</td></tr> ' . "\n" ,
253- $ classes [$ class ]['methods ' ][$ method ]['link ' ],
258+ $ this -> rebaseLink ( $ classes [$ class ]['methods ' ][$ method ]['link ' ], $ isRoot ) ,
254259 $ methodName ,
255260 $ method ,
256261 $ coverage
@@ -263,10 +268,11 @@ protected function insufficientCoverage(array $classes)
263268 /**
264269 * Returns the project risks according to the CRAP index.
265270 *
266- * @param array $classes
271+ * @param array $classes
272+ * @param boolean $isRoot
267273 * @return array
268274 */
269- protected function projectRisks (array $ classes )
275+ protected function projectRisks (array $ classes, $ isRoot )
270276 {
271277 $ classRisks = array ();
272278 $ methodRisks = array ();
@@ -298,7 +304,7 @@ protected function projectRisks(array $classes)
298304 foreach ($ classRisks as $ className => $ crap ) {
299305 $ result ['class ' ] .= sprintf (
300306 ' <tr><td><a href="%s">%s</a></td><td class="text-right">%d</td></tr> ' . "\n" ,
301- $ classes [$ className ]['link ' ],
307+ $ this -> rebaseLink ( $ classes [$ className ]['link ' ], $ isRoot ) ,
302308 $ className ,
303309 $ crap
304310 );
@@ -309,7 +315,7 @@ protected function projectRisks(array $classes)
309315
310316 $ result ['method ' ] .= sprintf (
311317 ' <tr><td><a href="%s"><abbr title="%s">%s</abbr></a></td><td class="text-right">%d</td></tr> ' . "\n" ,
312- $ classes [$ class ]['methods ' ][$ method ]['link ' ],
318+ $ this -> rebaseLink ( $ classes [$ class ]['methods ' ][$ method ]['link ' ], $ isRoot ) ,
313319 $ methodName ,
314320 $ method ,
315321 $ crap
@@ -327,4 +333,15 @@ protected function getActiveBreadcrumb(PHP_CodeCoverage_Report_Node $node)
327333 $ node ->getName ()
328334 );
329335 }
336+
337+ /**
338+ * @param string $link
339+ * @param boolean $isRoot
340+ * @return string
341+ * @since Method available since Release 2.0.12
342+ */
343+ private function rebaseLink ($ link , $ isRoot )
344+ {
345+ return $ isRoot ? $ link : substr ($ link , strpos ($ link , '/ ' ) + 1 );
346+ }
330347}
0 commit comments