Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Node/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,8 @@ private function calculatePathsAggregate(array $paths, &$functionExecutablePaths
$paths,
static function ($carry, $value) {
return ($value['hit'] > 0) ? $carry + 1 : $carry;
}
},
0
);
}

Expand Down
13 changes: 13 additions & 0 deletions src/Report/Html/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ final class Facade
*/
private $highLowerBound;

/**
* @var bool
*/
private $determineBranchCoverage = false;

public function __construct(int $lowUpperBound = 50, int $highLowerBound = 90, string $generator = '')
{
$this->generator = $generator;
Expand Down Expand Up @@ -69,6 +74,7 @@ public function process(CodeCoverage $coverage, string $target): void
$this->lowUpperBound,
$this->highLowerBound
);
$dashboard->setDetermineBranchCoverage($this->determineBranchCoverage);

$directory = new Directory(
$this->templatePath,
Expand All @@ -77,6 +83,7 @@ public function process(CodeCoverage $coverage, string $target): void
$this->lowUpperBound,
$this->highLowerBound
);
$directory->setDetermineBranchCoverage($this->determineBranchCoverage);

$file = new File(
$this->templatePath,
Expand All @@ -85,6 +92,7 @@ public function process(CodeCoverage $coverage, string $target): void
$this->lowUpperBound,
$this->highLowerBound
);
$file->setDetermineBranchCoverage($this->determineBranchCoverage);

$directory->render($report, $target . 'index.html');
$dashboard->render($report, $target . 'dashboard.html');
Expand Down Expand Up @@ -113,6 +121,11 @@ public function process(CodeCoverage $coverage, string $target): void
$this->copyFiles($target);
}

public function setDetermineBranchCoverage(bool $determineBranchCoverage): void
{
$this->determineBranchCoverage = $determineBranchCoverage;
}

/**
* @throws RuntimeException
*/
Expand Down
57 changes: 42 additions & 15 deletions src/Report/Html/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ abstract class Renderer
*/
protected $version;

/**
* @var bool
*/
protected $determineBranchCoverage = false;

public function __construct(string $templatePath, string $generator, string $date, int $lowUpperBound, int $highLowerBound)
{
$this->templatePath = $templatePath;
Expand All @@ -60,6 +65,11 @@ public function __construct(string $templatePath, string $generator, string $dat
$this->version = Version::id();
}

public function setDetermineBranchCoverage(bool $determineBranchCoverage): void
{
$this->determineBranchCoverage = $determineBranchCoverage;
}

protected function renderItemTemplate(\Text_Template $template, array $data): string
{
$numSeparator = ' / ';
Expand Down Expand Up @@ -112,23 +122,40 @@ protected function renderItemTemplate(\Text_Template $template, array $data): st
$data['linesExecutedPercentAsString'] = 'n/a';
}

$branchesLevel = '';
$branchesNumber = '0' . $numSeparator . '0';
$branchesBar = '';

// @todo - Remove the null coalesce
if (($data['numExecutableBranches'] ?? 0) > 0) {
$branchesLevel = $this->getColorLevel($data['testedBranchesPercent']);
$branchesBar = $this->getCoverageBar($data['testedBranchesPercent']);
$branchesNumber = $data['numExecutedBranches'] . $numSeparator . $data['numExecutableBranches'];
} else {
$data['testedBranchesPercentAsString'] = 'n/a';
}

$template->setVar(
[
'icon' => $data['icon'] ?? '',
'crap' => $data['crap'] ?? '',
'name' => $data['name'],
'lines_bar' => $linesBar,
'lines_executed_percent' => $data['linesExecutedPercentAsString'],
'lines_level' => $linesLevel,
'lines_number' => $linesNumber,
'methods_bar' => $methodsBar,
'methods_tested_percent' => $data['testedMethodsPercentAsString'],
'methods_level' => $methodsLevel,
'methods_number' => $methodsNumber,
'classes_bar' => $classesBar,
'classes_tested_percent' => $data['testedClassesPercentAsString'] ?? '',
'classes_level' => $classesLevel,
'classes_number' => $classesNumber,
'icon' => $data['icon'] ?? '',
'crap' => $data['crap'] ?? '',
'name' => $data['name'],
'lines_bar' => $linesBar,
'lines_executed_percent' => $data['linesExecutedPercentAsString'],
'lines_level' => $linesLevel,
'lines_number' => $linesNumber,
'methods_bar' => $methodsBar,
'methods_tested_percent' => $data['testedMethodsPercentAsString'],
'methods_level' => $methodsLevel,
'methods_number' => $methodsNumber,
'classes_bar' => $classesBar,
'classes_tested_percent' => $data['testedClassesPercentAsString'] ?? '',
'classes_level' => $classesLevel,
'classes_number' => $classesNumber,
'branches_bar' => $branchesBar,
'branches_tested_percent' => $data['testedBranchesPercentAsString'] ?? '',
'branches_level' => $branchesLevel,
'branches_number' => $branchesNumber,
]
);

Expand Down
48 changes: 33 additions & 15 deletions src/Report/Html/Renderer/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ final class Directory extends Renderer
*/
public function render(DirectoryNode $node, string $file): void
{
$template = new \Text_Template($this->templatePath . 'directory.html', '{{', '}}');
$templateName = $this->templatePath . 'directory.html';
if ($this->determineBranchCoverage) {
$templateName = $this->templatePath . 'directory_branch.html';
}

$template = new \Text_Template($templateName, '{{', '}}');

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

Expand All @@ -47,21 +52,29 @@ public function render(DirectoryNode $node, string $file): void
$template->renderTo($file);
}

protected function renderItem(Node $node, bool $total = false): string
private function renderItem(Node $node, bool $total = false): string
{
$data = [
'numClasses' => $node->getNumClassesAndTraits(),
'numTestedClasses' => $node->getNumTestedClassesAndTraits(),
'numMethods' => $node->getNumFunctionsAndMethods(),
'numTestedMethods' => $node->getNumTestedFunctionsAndMethods(),
'linesExecutedPercent' => $node->getLineExecutedPercent(false),
'linesExecutedPercentAsString' => $node->getLineExecutedPercent(),
'numExecutedLines' => $node->getNumExecutedLines(),
'numExecutableLines' => $node->getNumExecutableLines(),
'testedMethodsPercent' => $node->getTestedFunctionsAndMethodsPercent(false),
'testedMethodsPercentAsString' => $node->getTestedFunctionsAndMethodsPercent(),
'testedClassesPercent' => $node->getTestedClassesAndTraitsPercent(false),
'testedClassesPercentAsString' => $node->getTestedClassesAndTraitsPercent(),
'numClasses' => $node->getNumClassesAndTraits(),
'numTestedClasses' => $node->getNumTestedClassesAndTraits(),
'numMethods' => $node->getNumFunctionsAndMethods(),
'numTestedMethods' => $node->getNumTestedFunctionsAndMethods(),
'linesExecutedPercent' => $node->getLineExecutedPercent(false),
'linesExecutedPercentAsString' => $node->getLineExecutedPercent(),
'numExecutedLines' => $node->getNumExecutedLines(),
'numExecutableLines' => $node->getNumExecutableLines(),
'testedMethodsPercent' => $node->getTestedFunctionsAndMethodsPercent(false),
'testedMethodsPercentAsString' => $node->getTestedFunctionsAndMethodsPercent(),
'testedClassesPercent' => $node->getTestedClassesAndTraitsPercent(false),
'testedClassesPercentAsString' => $node->getTestedClassesAndTraitsPercent(),
'testedBranchesPercent' => $node->getTestedBranchesPercent(false),
'testedBranchesPercentAsString' => $node->getTestedBranchesPercent(),
'testedPathsPercent' => $node->getTestedPathsPercent(false),
'testedPathsPercentAsString' => $node->getTestedPathsPercent(),
'numExecutablePaths' => $node->getNumPaths(),
'numExecutedPaths' => $node->getNumTestedPaths(),
'numExecutableBranches' => $node->getNumBranches(),
'numExecutedBranches' => $node->getNumTestedBranches(),
];

if ($total) {
Expand Down Expand Up @@ -90,8 +103,13 @@ protected function renderItem(Node $node, bool $total = false): string
}
}

$templateName = $this->templatePath . 'directory_item.html';
if ($this->determineBranchCoverage) {
$templateName = $this->templatePath . 'directory_item_branch.html';
}

return $this->renderItemTemplate(
new \Text_Template($this->templatePath . 'directory_item.html', '{{', '}}'),
new \Text_Template($templateName, '{{', '}}'),
$data
);
}
Expand Down
Loading