Skip to content

Commit 31ab809

Browse files
committed
Make template files honor branch coverage feature flag
1 parent e7480c9 commit 31ab809

12 files changed

+210
-22
lines changed

src/Report/Html/Renderer/Directory.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ final class Directory extends Renderer
2323
*/
2424
public function render(DirectoryNode $node, string $file): void
2525
{
26-
$template = new \Text_Template($this->templatePath . 'directory.html', '{{', '}}');
26+
$templateName = $this->templatePath . 'directory.html';
27+
if ($this->determineBranchCoverage) {
28+
$templateName = $this->templatePath . 'directory_branch.html';
29+
}
30+
31+
$template = new \Text_Template($templateName, '{{', '}}');
2732

2833
$this->setCommonTemplateVariables($template, $node);
2934

@@ -98,8 +103,13 @@ private function renderItem(Node $node, bool $total = false): string
98103
}
99104
}
100105

106+
$templateName = $this->templatePath . 'directory_item.html';
107+
if ($this->determineBranchCoverage) {
108+
$templateName = $this->templatePath . 'directory_item_branch.html';
109+
}
110+
101111
return $this->renderItemTemplate(
102-
new \Text_Template($this->templatePath . 'directory_item.html', '{{', '}}'),
112+
new \Text_Template($templateName, '{{', '}}'),
103113
$data
104114
);
105115
}

src/Report/Html/Renderer/File.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ final class File extends Renderer
2727
*/
2828
public function render(FileNode $node, string $file): void
2929
{
30-
$template = new \Text_Template($this->templatePath . 'file.html', '{{', '}}');
30+
$templateName = $this->templatePath . 'file.html';
31+
if ($this->determineBranchCoverage) {
32+
$templateName = $this->templatePath . 'file_branch.html';
33+
}
34+
35+
$template = new \Text_Template($templateName, '{{', '}}');
3136

3237
$template->setVar(
3338
[
@@ -43,13 +48,16 @@ public function render(FileNode $node, string $file): void
4348

4449
protected function renderItems(FileNode $node): string
4550
{
46-
$template = new \Text_Template($this->templatePath . 'file_item.html', '{{', '}}');
51+
$fileTemplateName = $this->templatePath . 'file_item.html';
52+
$methodItemTemplateName = $this->templatePath . 'method_item.html';
4753

48-
$methodItemTemplate = new \Text_Template(
49-
$this->templatePath . 'method_item.html',
50-
'{{',
51-
'}}'
52-
);
54+
if ($this->determineBranchCoverage) {
55+
$fileTemplateName = $this->templatePath . 'file_item_branch.html';
56+
$methodItemTemplateName = $this->templatePath . 'method_item_branch.html';
57+
}
58+
59+
$template = new \Text_Template($fileTemplateName, '{{', '}}');
60+
$methodItemTemplate = new \Text_Template($methodItemTemplateName, '{{', '}}');
5361

5462
$items = $this->renderItemTemplate(
5563
$template,

src/Report/Html/Renderer/Template/directory.html.dist

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@
2929
<thead>
3030
<tr>
3131
<td>&nbsp;</td>
32-
<td colspan="12"><div align="center"><strong>Code Coverage</strong></div></td>
32+
<td colspan="9"><div align="center"><strong>Code Coverage</strong></div></td>
3333
</tr>
3434
<tr>
3535
<td>&nbsp;</td>
3636
<td colspan="3"><div align="center"><strong>Lines</strong></div></td>
37-
<td colspan="3"><div align="center"><strong>Branches</strong></div></td>
3837
<td colspan="3"><div align="center"><strong>Functions and Methods</strong></div></td>
3938
<td colspan="3"><div align="center"><strong>Classes and Traits</strong></div></td>
4039
</tr>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Code Coverage for {{full_path}}</title>
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<link href="{{path_to_root}}_css/bootstrap.min.css" rel="stylesheet" type="text/css">
8+
<link href="{{path_to_root}}_css/octicons.css" rel="stylesheet" type="text/css">
9+
<link href="{{path_to_root}}_css/style.css" rel="stylesheet" type="text/css">
10+
<link href="{{path_to_root}}_css/custom.css" rel="stylesheet" type="text/css">
11+
</head>
12+
<body>
13+
<header>
14+
<div class="container-fluid">
15+
<div class="row">
16+
<div class="col-md-12">
17+
<nav aria-label="breadcrumb">
18+
<ol class="breadcrumb">
19+
{{breadcrumbs}}
20+
</ol>
21+
</nav>
22+
</div>
23+
</div>
24+
</div>
25+
</header>
26+
<div class="container-fluid">
27+
<div class="table-responsive">
28+
<table class="table table-bordered">
29+
<thead>
30+
<tr>
31+
<td>&nbsp;</td>
32+
<td colspan="12"><div align="center"><strong>Code Coverage</strong></div></td>
33+
</tr>
34+
<tr>
35+
<td>&nbsp;</td>
36+
<td colspan="3"><div align="center"><strong>Lines</strong></div></td>
37+
<td colspan="3"><div align="center"><strong>Branches</strong></div></td>
38+
<td colspan="3"><div align="center"><strong>Functions and Methods</strong></div></td>
39+
<td colspan="3"><div align="center"><strong>Classes and Traits</strong></div></td>
40+
</tr>
41+
</thead>
42+
<tbody>
43+
{{items}}
44+
</tbody>
45+
</table>
46+
</div>
47+
<footer>
48+
<hr/>
49+
<h4>Legend</h4>
50+
<p>
51+
<span class="danger"><strong>Low</strong>: 0% to {{low_upper_bound}}%</span>
52+
<span class="warning"><strong>Medium</strong>: {{low_upper_bound}}% to {{high_lower_bound}}%</span>
53+
<span class="success"><strong>High</strong>: {{high_lower_bound}}% to 100%</span>
54+
</p>
55+
<p>
56+
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage {{version}}</a> using {{runtime}}{{generator}} at {{date}}.</small>
57+
</p>
58+
</footer>
59+
</div>
60+
</body>
61+
</html>

src/Report/Html/Renderer/Template/directory_item.html.dist

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
<td class="{{lines_level}} big">{{lines_bar}}</td>
44
<td class="{{lines_level}} small"><div align="right">{{lines_executed_percent}}</div></td>
55
<td class="{{lines_level}} small"><div align="right">{{lines_number}}</div></td>
6-
<td class="{{branches_level}} big">{{branches_bar}}</td>
7-
<td class="{{branches_level}} small"><div align="right">{{branches_tested_percent}}</div></td>
8-
<td class="{{branches_level}} small"><div align="right">{{branches_number}}</div></td>
96
<td class="{{methods_level}} big">{{methods_bar}}</td>
107
<td class="{{methods_level}} small"><div align="right">{{methods_tested_percent}}</div></td>
118
<td class="{{methods_level}} small"><div align="right">{{methods_number}}</div></td>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<tr>
2+
<td class="{{lines_level}}">{{icon}}{{name}}</td>
3+
<td class="{{lines_level}} big">{{lines_bar}}</td>
4+
<td class="{{lines_level}} small"><div align="right">{{lines_executed_percent}}</div></td>
5+
<td class="{{lines_level}} small"><div align="right">{{lines_number}}</div></td>
6+
<td class="{{branches_level}} big">{{branches_bar}}</td>
7+
<td class="{{branches_level}} small"><div align="right">{{branches_tested_percent}}</div></td>
8+
<td class="{{branches_level}} small"><div align="right">{{branches_number}}</div></td>
9+
<td class="{{methods_level}} big">{{methods_bar}}</td>
10+
<td class="{{methods_level}} small"><div align="right">{{methods_tested_percent}}</div></td>
11+
<td class="{{methods_level}} small"><div align="right">{{methods_number}}</div></td>
12+
<td class="{{classes_level}} big">{{classes_bar}}</td>
13+
<td class="{{classes_level}} small"><div align="right">{{classes_tested_percent}}</div></td>
14+
<td class="{{classes_level}} small"><div align="right">{{classes_number}}</div></td>
15+
</tr>
16+

src/Report/Html/Renderer/Template/file.html.dist

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@
2929
<thead>
3030
<tr>
3131
<td>&nbsp;</td>
32-
<td colspan="13"><div align="center"><strong>Code Coverage</strong></div></td>
32+
<td colspan="10"><div align="center"><strong>Code Coverage</strong></div></td>
3333
</tr>
3434
<tr>
3535
<td>&nbsp;</td>
3636
<td colspan="3"><div align="center"><strong>Classes and Traits</strong></div></td>
3737
<td colspan="4"><div align="center"><strong>Functions and Methods</strong></div></td>
38-
<td colspan="3"><div align="center"><strong>Branches</strong></div></td>
3938
<td colspan="3"><div align="center"><strong>Lines</strong></div></td>
4039
</tr>
4140
</thead>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Code Coverage for {{full_path}}</title>
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<link href="{{path_to_root}}_css/bootstrap.min.css" rel="stylesheet" type="text/css">
8+
<link href="{{path_to_root}}_css/octicons.css" rel="stylesheet" type="text/css">
9+
<link href="{{path_to_root}}_css/style.css" rel="stylesheet" type="text/css">
10+
<link href="{{path_to_root}}_css/custom.css" rel="stylesheet" type="text/css">
11+
</head>
12+
<body>
13+
<header>
14+
<div class="container-fluid">
15+
<div class="row">
16+
<div class="col-md-12">
17+
<nav aria-label="breadcrumb">
18+
<ol class="breadcrumb">
19+
{{breadcrumbs}}
20+
</ol>
21+
</nav>
22+
</div>
23+
</div>
24+
</div>
25+
</header>
26+
<div class="container-fluid">
27+
<div class="table-responsive">
28+
<table class="table table-bordered">
29+
<thead>
30+
<tr>
31+
<td>&nbsp;</td>
32+
<td colspan="13"><div align="center"><strong>Code Coverage</strong></div></td>
33+
</tr>
34+
<tr>
35+
<td>&nbsp;</td>
36+
<td colspan="3"><div align="center"><strong>Classes and Traits</strong></div></td>
37+
<td colspan="4"><div align="center"><strong>Functions and Methods</strong></div></td>
38+
<td colspan="3"><div align="center"><strong>Branches</strong></div></td>
39+
<td colspan="3"><div align="center"><strong>Lines</strong></div></td>
40+
</tr>
41+
</thead>
42+
<tbody>
43+
{{items}}
44+
</tbody>
45+
</table>
46+
</div>
47+
<table id="code" class="table table-borderless table-condensed">
48+
<tbody>
49+
{{lines}}
50+
</tbody>
51+
</table>
52+
<footer>
53+
<hr/>
54+
<h4>Legend</h4>
55+
<p>
56+
<span class="success"><strong>Executed</strong></span>
57+
<span class="danger"><strong>Not Executed</strong></span>
58+
<span class="warning"><strong>Dead Code</strong></span>
59+
</p>
60+
<p>
61+
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage {{version}}</a> using {{runtime}}{{generator}} at {{date}}.</small>
62+
</p>
63+
<a title="Back to the top" id="toplink" href="#">
64+
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="16" viewBox="0 0 12 16"><path fill-rule="evenodd" d="M12 11L6 5l-6 6h12z"/></svg>
65+
</a>
66+
</footer>
67+
</div>
68+
<script src="{{path_to_root}}_js/jquery.min.js" type="text/javascript"></script>
69+
<script src="{{path_to_root}}_js/popper.min.js" type="text/javascript"></script>
70+
<script src="{{path_to_root}}_js/bootstrap.min.js" type="text/javascript"></script>
71+
<script src="{{path_to_root}}_js/file.js" type="text/javascript"></script>
72+
</body>
73+
</html>

src/Report/Html/Renderer/Template/file_item.html.dist

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
<td class="{{methods_level}} small"><div align="right">{{methods_tested_percent}}</div></td>
88
<td class="{{methods_level}} small"><div align="right">{{methods_number}}</div></td>
99
<td class="{{methods_level}} small">{{crap}}</td>
10-
<td class="{{branches_level}} big">{{branches_bar}}</td>
11-
<td class="{{branches_level}} small"><div align="right">{{branches_tested_percent}}</div></td>
12-
<td class="{{branches_level}} small"><div align="right">{{branches_number}}</div></td>
1310
<td class="{{lines_level}} big">{{lines_bar}}</td>
1411
<td class="{{lines_level}} small"><div align="right">{{lines_executed_percent}}</div></td>
1512
<td class="{{lines_level}} small"><div align="right">{{lines_number}}</div></td>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<tr>
2+
<td class="{{classes_level}}">{{name}}</td>
3+
<td class="{{classes_level}} big">{{classes_bar}}</td>
4+
<td class="{{classes_level}} small"><div align="right">{{classes_tested_percent}}</div></td>
5+
<td class="{{classes_level}} small"><div align="right">{{classes_number}}</div></td>
6+
<td class="{{methods_level}} big">{{methods_bar}}</td>
7+
<td class="{{methods_level}} small"><div align="right">{{methods_tested_percent}}</div></td>
8+
<td class="{{methods_level}} small"><div align="right">{{methods_number}}</div></td>
9+
<td class="{{methods_level}} small">{{crap}}</td>
10+
<td class="{{branches_level}} big">{{branches_bar}}</td>
11+
<td class="{{branches_level}} small"><div align="right">{{branches_tested_percent}}</div></td>
12+
<td class="{{branches_level}} small"><div align="right">{{branches_number}}</div></td>
13+
<td class="{{lines_level}} big">{{lines_bar}}</td>
14+
<td class="{{lines_level}} small"><div align="right">{{lines_executed_percent}}</div></td>
15+
<td class="{{lines_level}} small"><div align="right">{{lines_number}}</div></td>
16+
</tr>
17+

0 commit comments

Comments
 (0)