Skip to content

Commit cb41d1f

Browse files
Refactor.
1 parent 856670c commit cb41d1f

File tree

3 files changed

+41
-17
lines changed

3 files changed

+41
-17
lines changed

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

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,23 +115,56 @@ public function render(PHP_CodeCoverage_Report_Node_File $node, $file, $title =
115115

116116
if ($this->yui) {
117117
$template = new Text_Template($this->templatePath . 'file.html');
118-
119-
$yuiTemplate = new Text_Template(
120-
$this->templatePath . 'yui_item.js'
121-
);
122118
} else {
123119
$template = new Text_Template(
124120
$this->templatePath . 'file_no_yui.html'
125121
);
126122
}
127123

124+
list($source, $yuiTemplate) = $this->renderSource($node);
125+
126+
$template->setVar(
127+
array(
128+
'items' => $this->renderItems($node),
129+
'source' => $source,
130+
'yuiTemplate' => $yuiTemplate
131+
)
132+
);
133+
134+
$this->setCommonTemplateVariables($template, $title, $node);
135+
136+
$template->renderTo($file);
137+
}
138+
139+
/**
140+
* @param PHP_CodeCoverage_Report_Node_File $node
141+
* @return string
142+
*/
143+
protected function renderItems(PHP_CodeCoverage_Report_Node_File $node)
144+
{
128145
$items = '';
129146

147+
return $items;
148+
}
149+
150+
/**
151+
* @param PHP_CodeCoverage_Report_Node_File $node
152+
* @return string
153+
*/
154+
protected function renderSource(PHP_CodeCoverage_Report_Node_File $node)
155+
{
156+
if ($this->yui) {
157+
$yuiTemplate = new Text_Template(
158+
$this->templatePath . 'yui_item.js'
159+
);
160+
}
161+
130162
$coverageData = $node->getCoverageData();
131163
$ignoredLines = $node->getIgnoredLines();
132164
$testData = $node->getTestData();
133165
list($codeLines, $fillup) = $this->loadFile($node->getPath());
134166
$lines = '';
167+
$yuiPanelJS = '';
135168
$i = 1;
136169

137170
foreach ($codeLines as $line) {
@@ -212,7 +245,7 @@ public function render(PHP_CodeCoverage_Report_Node_File $node, $file, $title =
212245
FALSE
213246
);
214247

215-
$this->yuiPanelJS .= $yuiTemplate->render();
248+
$yuiPanelJS .= $yuiTemplate->render();
216249
}
217250
}
218251

@@ -247,16 +280,7 @@ public function render(PHP_CodeCoverage_Report_Node_File $node, $file, $title =
247280
$i++;
248281
}
249282

250-
$template->setVar(
251-
array(
252-
'items' => $items,
253-
'lines' => $lines
254-
)
255-
);
256-
257-
$this->setCommonTemplateVariables($template, $title, $node);
258-
259-
$template->renderTo($file);
283+
return array($lines, $yuiPanelJS);
260284
}
261285

262286
/**

PHP/CodeCoverage/Report/HTML/Renderer/Template/file.html.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
<tr>
6767
<td>
6868
<pre class="source">
69-
{lines}
69+
{source}
7070
</pre>
7171
</td>
7272
</tr>

PHP/CodeCoverage/Report/HTML/Renderer/Template/file_no_yui.html.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
<tr>
6464
<td>
6565
<pre class="source">
66-
{lines}
66+
{source}
6767
</pre>
6868
</td>
6969
</tr>

0 commit comments

Comments
 (0)