| 148 |
lars |
1 |
<?php declare(strict_types=1);
|
|
|
2 |
/*
|
|
|
3 |
* This file is part of phpunit/php-code-coverage.
|
|
|
4 |
*
|
|
|
5 |
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
|
|
6 |
*
|
|
|
7 |
* For the full copyright and license information, please view the LICENSE
|
|
|
8 |
* file that was distributed with this source code.
|
|
|
9 |
*/
|
|
|
10 |
namespace SebastianBergmann\CodeCoverage\Report\Html;
|
|
|
11 |
|
|
|
12 |
use function count;
|
|
|
13 |
use function sprintf;
|
|
|
14 |
use function str_repeat;
|
|
|
15 |
use SebastianBergmann\CodeCoverage\Node\AbstractNode as Node;
|
|
|
16 |
use SebastianBergmann\CodeCoverage\Node\Directory as DirectoryNode;
|
|
|
17 |
use SebastianBergmann\Template\Template;
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
|
|
|
21 |
*/
|
|
|
22 |
final class Directory extends Renderer
|
|
|
23 |
{
|
|
|
24 |
public function render(DirectoryNode $node, string $file): void
|
|
|
25 |
{
|
|
|
26 |
$templateName = $this->templatePath . ($this->hasBranchCoverage ? 'directory_branch.html' : 'directory.html');
|
|
|
27 |
$template = new Template($templateName, '{{', '}}');
|
|
|
28 |
|
|
|
29 |
$this->setCommonTemplateVariables($template, $node);
|
|
|
30 |
|
|
|
31 |
$items = $this->renderItem($node, true);
|
|
|
32 |
|
|
|
33 |
foreach ($node->directories() as $item) {
|
|
|
34 |
$items .= $this->renderItem($item);
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
foreach ($node->files() as $item) {
|
|
|
38 |
$items .= $this->renderItem($item);
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
$template->setVar(
|
|
|
42 |
[
|
|
|
43 |
'id' => $node->id(),
|
|
|
44 |
'items' => $items,
|
|
|
45 |
]
|
|
|
46 |
);
|
|
|
47 |
|
|
|
48 |
$template->renderTo($file);
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
private function renderItem(Node $node, bool $total = false): string
|
|
|
52 |
{
|
|
|
53 |
$data = [
|
|
|
54 |
'numClasses' => $node->numberOfClassesAndTraits(),
|
|
|
55 |
'numTestedClasses' => $node->numberOfTestedClassesAndTraits(),
|
|
|
56 |
'numMethods' => $node->numberOfFunctionsAndMethods(),
|
|
|
57 |
'numTestedMethods' => $node->numberOfTestedFunctionsAndMethods(),
|
|
|
58 |
'linesExecutedPercent' => $node->percentageOfExecutedLines()->asFloat(),
|
|
|
59 |
'linesExecutedPercentAsString' => $node->percentageOfExecutedLines()->asString(),
|
|
|
60 |
'numExecutedLines' => $node->numberOfExecutedLines(),
|
|
|
61 |
'numExecutableLines' => $node->numberOfExecutableLines(),
|
|
|
62 |
'branchesExecutedPercent' => $node->percentageOfExecutedBranches()->asFloat(),
|
|
|
63 |
'branchesExecutedPercentAsString' => $node->percentageOfExecutedBranches()->asString(),
|
|
|
64 |
'numExecutedBranches' => $node->numberOfExecutedBranches(),
|
|
|
65 |
'numExecutableBranches' => $node->numberOfExecutableBranches(),
|
|
|
66 |
'pathsExecutedPercent' => $node->percentageOfExecutedPaths()->asFloat(),
|
|
|
67 |
'pathsExecutedPercentAsString' => $node->percentageOfExecutedPaths()->asString(),
|
|
|
68 |
'numExecutedPaths' => $node->numberOfExecutedPaths(),
|
|
|
69 |
'numExecutablePaths' => $node->numberOfExecutablePaths(),
|
|
|
70 |
'testedMethodsPercent' => $node->percentageOfTestedFunctionsAndMethods()->asFloat(),
|
|
|
71 |
'testedMethodsPercentAsString' => $node->percentageOfTestedFunctionsAndMethods()->asString(),
|
|
|
72 |
'testedClassesPercent' => $node->percentageOfTestedClassesAndTraits()->asFloat(),
|
|
|
73 |
'testedClassesPercentAsString' => $node->percentageOfTestedClassesAndTraits()->asString(),
|
|
|
74 |
];
|
|
|
75 |
|
|
|
76 |
if ($total) {
|
|
|
77 |
$data['name'] = 'Total';
|
|
|
78 |
} else {
|
|
|
79 |
$up = str_repeat('../', count($node->pathAsArray()) - 2);
|
|
|
80 |
$data['icon'] = sprintf('<img src="%s_icons/file-code.svg" class="octicon" />', $up);
|
|
|
81 |
|
|
|
82 |
if ($node instanceof DirectoryNode) {
|
|
|
83 |
$data['name'] = sprintf(
|
|
|
84 |
'<a href="%s/index.html">%s</a>',
|
|
|
85 |
$node->name(),
|
|
|
86 |
$node->name()
|
|
|
87 |
);
|
|
|
88 |
$data['icon'] = sprintf('<img src="%s_icons/file-directory.svg" class="octicon" />', $up);
|
|
|
89 |
} elseif ($this->hasBranchCoverage) {
|
|
|
90 |
$data['name'] = sprintf(
|
|
|
91 |
'%s <a class="small" href="%s.html">[line]</a> <a class="small" href="%s_branch.html">[branch]</a> <a class="small" href="%s_path.html">[path]</a>',
|
|
|
92 |
$node->name(),
|
|
|
93 |
$node->name(),
|
|
|
94 |
$node->name(),
|
|
|
95 |
$node->name()
|
|
|
96 |
);
|
|
|
97 |
} else {
|
|
|
98 |
$data['name'] = sprintf(
|
|
|
99 |
'<a href="%s.html">%s</a>',
|
|
|
100 |
$node->name(),
|
|
|
101 |
$node->name()
|
|
|
102 |
);
|
|
|
103 |
}
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
$templateName = $this->templatePath . ($this->hasBranchCoverage ? 'directory_item_branch.html' : 'directory_item.html');
|
|
|
107 |
|
|
|
108 |
return $this->renderItemTemplate(
|
|
|
109 |
new Template($templateName, '{{', '}}'),
|
|
|
110 |
$data
|
|
|
111 |
);
|
|
|
112 |
}
|
|
|
113 |
}
|