Permalink
Browse files

Reduce code duplication

  • Loading branch information...
1 parent 6b99bb6 commit cd34dc4cbb16810059a8f474432b0516b2310186 @sebastianbergmann committed Feb 11, 2013
Showing with 37 additions and 38 deletions.
  1. +30 −15 PHP/CodeCoverage/Report/HTML/Renderer.php
  2. +7 −23 PHP/CodeCoverage/Report/HTML/Renderer/Dashboard.php
@@ -211,29 +211,44 @@ protected function getBreadcrumbs(PHP_CodeCoverage_Report_Node $node)
foreach ($path as $step) {
if ($step !== $node) {
- $breadcrumbs .= sprintf(
- ' <li><a href="%s.html">%s</a> <span class="divider">/</span></li>' . "\n",
- $step->getId(),
- $step->getName()
- );
+ $breadcrumbs .= $this->getInactiveBreadcrumb($step);
} else {
- $breadcrumbs .= sprintf(
- ' <li class="active">%s</li>' . "\n",
- $step->getName()
+ $breadcrumbs .= $this->getActiveBreadcrumb(
+ $step,
+ $node instanceof PHP_CodeCoverage_Report_Node_Directory
);
-
- if ($node instanceof PHP_CodeCoverage_Report_Node_Directory) {
- $breadcrumbs .= sprintf(
- ' <li>(<a href="%s.dashboard.html">Dashboard</a>)</li>' . "\n",
- $step->getId()
- );
- }
}
}
return $breadcrumbs;
}
+ protected function getActiveBreadcrumb(PHP_CodeCoverage_Report_Node $node, $isDirectory)
+ {
+ $buffer = sprintf(
+ ' <li class="active">%s</li>' . "\n",
+ $node->getName()
+ );
+
+ if ($isDirectory) {
+ $buffer .= sprintf(
+ ' <li>(<a href="%s.dashboard.html">Dashboard</a>)</li>' . "\n",
+ $node->getId()
+ );
+ }
+
+ return $buffer;
+ }
+
+ protected function getInactiveBreadcrumb(PHP_CodeCoverage_Report_Node $node)
+ {
+ return sprintf(
+ ' <li><a href="%s.html">%s</a> <span class="divider">/</span></li>' . "\n",
+ $node->getId(),
+ $node->getName()
+ );
+ }
+
protected function getCoverageBar($percent)
{
$level = $this->getColorLevel($percent);
@@ -228,29 +228,13 @@ protected function topProjectRisks(array $classes, $max = 10)
return $buffer;
}
- protected function getBreadcrumbs(PHP_CodeCoverage_Report_Node $node)
+ protected function getActiveBreadcrumb(PHP_CodeCoverage_Report_Node $node, $isDirectory)
{
- $breadcrumbs = '';
-
- $path = $node->getPathAsArray();
-
- foreach ($path as $step) {
- if ($step !== $node) {
- $breadcrumbs .= sprintf(
- ' <li><a href="%s.html">%s</a> <span class="divider">/</span></li>' . "\n",
- $step->getId(),
- $step->getName()
- );
- } else {
- $breadcrumbs .= sprintf(
- ' <li><a href="%s.html">%s</a></li>' . "\n" .
- ' <li class="active">(Dashboard)</li>' . "\n",
- $step->getId(),
- $step->getName()
- );
- }
- }
-
- return $breadcrumbs;
+ return sprintf(
+ ' <li><a href="%s.html">%s</a></li>' . "\n" .
+ ' <li class="active">(Dashboard)</li>' . "\n",
+ $node->getId(),
+ $node->getName()
+ );
}
}

0 comments on commit cd34dc4

Please sign in to comment.