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

Breadcrumb

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

function File::loadFile

5 calls to File::loadFile()
File::renderBranchStructure in vendor/phpunit/php-code-coverage/src/Report/Html/Renderer/File.php
File::renderPathStructure in vendor/phpunit/php-code-coverage/src/Report/Html/Renderer/File.php
File::renderSourceWithBranchCoverage in vendor/phpunit/php-code-coverage/src/Report/Html/Renderer/File.php
File::renderSourceWithLineCoverage in vendor/phpunit/php-code-coverage/src/Report/Html/Renderer/File.php
File::renderSourceWithPathCoverage 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 974

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 loadFile(string $file) : array {
    if (isset(self::$formattedSourceCache[$file])) {
        return self::$formattedSourceCache[$file];
    }
    $buffer = file_get_contents($file);
    $tokens = token_get_all($buffer);
    $result = [
        '',
    ];
    $i = 0;
    $stringFlag = false;
    $fileEndsWithNewLine = str_ends_with($buffer, "\n");
    unset($buffer);
    foreach ($tokens as $j => $token) {
        if (is_string($token)) {
            if ($token === '"' && $tokens[$j - 1] !== '\\') {
                $result[$i] .= sprintf('<span class="string">%s</span>', htmlspecialchars($token, $this->htmlSpecialCharsFlags));
                $stringFlag = !$stringFlag;
            }
            else {
                $result[$i] .= sprintf('<span class="keyword">%s</span>', htmlspecialchars($token, $this->htmlSpecialCharsFlags));
            }
            continue;
        }
        [
            $token,
            $value,
        ] = $token;
        $value = str_replace([
            "\t",
            ' ',
        ], [
            '&nbsp;&nbsp;&nbsp;&nbsp;',
            '&nbsp;',
        ], htmlspecialchars($value, $this->htmlSpecialCharsFlags));
        if ($value === "\n") {
            $result[++$i] = '';
        }
        else {
            $lines = explode("\n", $value);
            foreach ($lines as $jj => $line) {
                $line = trim($line);
                if ($line !== '') {
                    if ($stringFlag) {
                        $colour = 'string';
                    }
                    else {
                        $colour = 'default';
                        if ($this->isInlineHtml($token)) {
                            $colour = 'html';
                        }
                        elseif ($this->isComment($token)) {
                            $colour = 'comment';
                        }
                        elseif ($this->isKeyword($token)) {
                            $colour = 'keyword';
                        }
                    }
                    $result[$i] .= sprintf('<span class="%s">%s</span>', $colour, $line);
                }
                if (isset($lines[$jj + 1])) {
                    $result[++$i] = '';
                }
            }
        }
    }
    if ($fileEndsWithNewLine) {
        unset($result[count($result) - 1]);
    }
    self::$formattedSourceCache[$file] = $result;
    return $result;
}

API Navigation

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