function File::renderBranchLines
1 call to File::renderBranchLines()
- File::renderBranchStructure in vendor/
phpunit/ php-code-coverage/ src/ Report/ Html/ Renderer/ File.php
File
-
vendor/
phpunit/ php-code-coverage/ src/ Report/ Html/ Renderer/ File.php, line 777
Class
- File
- @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
Namespace
SebastianBergmann\CodeCoverage\Report\HtmlCode
private function renderBranchLines(array $branch, array $codeLines, array $testData) : string {
$linesTemplate = new Template($this->templatePath . 'lines.html.dist', '{{', '}}');
$singleLineTemplate = new Template($this->templatePath . 'line.html.dist', '{{', '}}');
$lines = '';
$branchLines = range($branch['line_start'], $branch['line_end']);
sort($branchLines);
// sometimes end_line < start_line
/** @var int $line */
foreach ($branchLines as $line) {
if (!isset($codeLines[$line])) {
// blank line at end of file is sometimes included here
continue;
}
$popoverContent = '';
$popoverTitle = '';
$numTests = count($branch['hit']);
if ($numTests === 0) {
$trClass = 'danger';
}
else {
$lineCss = 'covered-by-large-tests';
$popoverContent = '<ul>';
if ($numTests > 1) {
$popoverTitle = $numTests . ' tests cover this branch';
}
else {
$popoverTitle = '1 test covers this branch';
}
foreach ($branch['hit'] as $test) {
if ($lineCss === 'covered-by-large-tests' && $testData[$test]['size'] === 'medium') {
$lineCss = 'covered-by-medium-tests';
}
elseif ($testData[$test]['size'] === 'small') {
$lineCss = 'covered-by-small-tests';
}
$popoverContent .= $this->createPopoverContentForTest($test, $testData[$test]);
}
$trClass = $lineCss . ' popin';
}
$popover = '';
if (!empty($popoverTitle)) {
$popover = sprintf(' data-title="%s" data-content="%s" data-placement="top" data-html="true"', $popoverTitle, htmlspecialchars($popoverContent, $this->htmlSpecialCharsFlags));
}
$lines .= $this->renderLine($singleLineTemplate, $line, $codeLines[$line - 1], $trClass, $popover);
}
if ($lines === '') {
return '';
}
$linesTemplate->setVar([
'lines' => $lines,
]);
return $linesTemplate->render();
}