Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. File.php

function File::renderPathLines

1 call to File::renderPathLines()
File::renderPathStructure 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 883

Class

File
@internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage

Namespace

SebastianBergmann\CodeCoverage\Report\Html

Code

private function renderPathLines(array $path, array $branches, array $codeLines, array $testData) : string {
    $linesTemplate = new Template($this->templatePath . 'lines.html.dist', '{{', '}}');
    $singleLineTemplate = new Template($this->templatePath . 'line.html.dist', '{{', '}}');
    $lines = '';
    $first = true;
    foreach ($path['path'] as $branchId) {
        if ($first) {
            $first = false;
        }
        else {
            $lines .= '    <tr><td colspan="2">&nbsp;</td></tr>' . "\n";
        }
        $branchLines = range($branches[$branchId]['line_start'], $branches[$branchId]['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($path['hit']);
            if ($numTests === 0) {
                $trClass = 'danger';
            }
            else {
                $lineCss = 'covered-by-large-tests';
                $popoverContent = '<ul>';
                if ($numTests > 1) {
                    $popoverTitle = $numTests . ' tests cover this path';
                }
                else {
                    $popoverTitle = '1 test covers this path';
                }
                foreach ($path['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();
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal