Skip to content

Commit 9b4d3a1

Browse files
Refactor.
1 parent 36b0082 commit 9b4d3a1

File tree

6 files changed

+34
-31
lines changed

6 files changed

+34
-31
lines changed

PHP/CodeCoverage/Report/HTML.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public function process(PHP_CodeCoverage $coverage, $target)
171171
$directory->render($report, $target . 'index.html', $this->title);
172172

173173
foreach ($report as $node) {
174-
$id = PHP_CodeCoverage_Util::nodeToId($node);
174+
$id = $node->getId();
175175

176176
if ($node instanceof PHP_CodeCoverage_Report_Node_Directory) {
177177
$dashboard->render($node, $target . $id . '.dashboard.html');

PHP/CodeCoverage/Report/HTML/Renderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ protected function setCommonTemplateVariables(Text_Template $template, $title, P
123123
$link .= sprintf(
124124
'%s<a href="%s.html">%s</a>',
125125
!empty($link) ? ' / ' : '',
126-
PHP_CodeCoverage_Util::nodeToId($step),
126+
$step->getId(),
127127
$step->getName()
128128
);
129129
}

PHP/CodeCoverage/Report/HTML/Renderer/Directory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function render(PHP_CodeCoverage_Report_Node_Directory $node, $file, $tit
8484

8585
$template->setVar(
8686
array(
87-
'id' => PHP_CodeCoverage_Util::nodeToId($node),
87+
'id' => $node->getId(),
8888
'items' => $items
8989
)
9090
);
@@ -110,7 +110,7 @@ protected function renderItem(PHP_CodeCoverage_Report_Node $item, $total = FALSE
110110
} else {
111111
$name = sprintf(
112112
'<a href="%s.html">%s</a>',
113-
PHP_CodeCoverage_Util::nodeToId($item),
113+
$item->getId(),
114114
$item->getName()
115115
);
116116

PHP/CodeCoverage/Report/Node.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ abstract class PHP_CodeCoverage_Report_Node implements Countable
7777
*/
7878
protected $parent;
7979

80+
/**
81+
* @var string
82+
*/
83+
protected $id;
84+
8085
/**
8186
* Constructor.
8287
*
@@ -101,6 +106,30 @@ public function getName()
101106
return $this->name;
102107
}
103108

109+
/**
110+
* @return string
111+
*/
112+
public function getId()
113+
{
114+
if ($this->id === NULL) {
115+
$parent = $this->getParent();
116+
117+
if ($parent === NULL) {
118+
$this->id = 'index';
119+
} else {
120+
$parentId = $parent->getId();
121+
122+
if ($parentId == 'index') {
123+
$this->id = $this->name;
124+
} else {
125+
$this->id = $parentId . '_' . $this->name;
126+
}
127+
}
128+
}
129+
130+
return $this->id;
131+
}
132+
104133
/**
105134
* @return string
106135
*/

PHP/CodeCoverage/Report/Node/File.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ protected function processClasses(PHP_Token_Stream $tokens)
485485
$classes = $tokens->getClasses();
486486
unset($tokens);
487487

488-
$link = PHP_CodeCoverage_Util::nodeToId($this) . '.html#';
488+
$link = $this->getId() . '.html#';
489489

490490
foreach ($classes as $className => $class) {
491491
$this->classes[$className] = array(

PHP/CodeCoverage/Util.php

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -469,32 +469,6 @@ public static function reducePaths(&$files)
469469
return substr($commonPath, 0, -1);
470470
}
471471

472-
/**
473-
* @param PHP_CodeCoverage_Report_Node $node
474-
* @return string
475-
*/
476-
public static function nodeToId(PHP_CodeCoverage_Report_Node $node)
477-
{
478-
if (!isset(self::$ids[$node->getPath()])) {
479-
$parent = $node->getParent();
480-
481-
if ($parent === NULL) {
482-
self::$ids[$node->getPath()] = 'index';
483-
} else {
484-
$parentId = self::nodeToId($parent);
485-
486-
if ($parentId == 'index') {
487-
self::$ids[$node->getPath()] = $node->getName();
488-
} else {
489-
self::$ids[$node->getPath()] = $parentId . '_' .
490-
$node->getName();
491-
}
492-
}
493-
}
494-
495-
return self::$ids[$node->getPath()];
496-
}
497-
498472
/**
499473
* @param string $coveredElement
500474
* @return array

0 commit comments

Comments
 (0)