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

Breadcrumb

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

class Facade

Same name in this branch
  1. 11.1.x vendor/phpunit/php-code-coverage/src/Report/Xml/Facade.php \SebastianBergmann\CodeCoverage\Report\Xml\Facade
  2. 11.1.x vendor/phpunit/phpunit/src/TextUI/Output/Facade.php \PHPUnit\TextUI\Output\Facade
  3. 11.1.x vendor/phpunit/phpunit/src/Event/Facade.php \PHPUnit\Event\Facade
  4. 11.1.x vendor/phpunit/phpunit/src/Runner/Extension/Facade.php \PHPUnit\Runner\Extension\Facade
  5. 11.1.x vendor/phpunit/phpunit/src/Runner/TestResult/Facade.php \PHPUnit\TestRunner\TestResult\Facade
  6. 11.1.x vendor/phpunit/php-file-iterator/src/Facade.php \SebastianBergmann\FileIterator\Facade

Hierarchy

  • class \SebastianBergmann\CodeCoverage\Report\Html\Facade

Expanded class hierarchy of Facade

1 file declares its use of Facade
CodeCoverage.php in vendor/phpunit/phpunit/src/Runner/CodeCoverage.php

File

vendor/phpunit/php-code-coverage/src/Report/Html/Facade.php, line 25

Namespace

SebastianBergmann\CodeCoverage\Report\Html
View source
final class Facade {
    private readonly string $templatePath;
    private readonly string $generator;
    private readonly Colors $colors;
    private readonly Thresholds $thresholds;
    private readonly CustomCssFile $customCssFile;
    public function __construct(string $generator = '', ?Colors $colors = null, ?Thresholds $thresholds = null, ?CustomCssFile $customCssFile = null) {
        $this->generator = $generator;
        $this->colors = $colors ?? Colors::default();
        $this->thresholds = $thresholds ?? Thresholds::default();
        $this->customCssFile = $customCssFile ?? CustomCssFile::default();
        $this->templatePath = __DIR__ . '/Renderer/Template/';
    }
    public function process(CodeCoverage $coverage, string $target) : void {
        $target = $this->directory($target);
        $report = $coverage->getReport();
        $date = date('D M j G:i:s T Y');
        $dashboard = new Dashboard($this->templatePath, $this->generator, $date, $this->thresholds, $coverage->collectsBranchAndPathCoverage());
        $directory = new Directory($this->templatePath, $this->generator, $date, $this->thresholds, $coverage->collectsBranchAndPathCoverage());
        $file = new File($this->templatePath, $this->generator, $date, $this->thresholds, $coverage->collectsBranchAndPathCoverage());
        $directory->render($report, $target . 'index.html');
        $dashboard->render($report, $target . 'dashboard.html');
        foreach ($report as $node) {
            $id = $node->id();
            if ($node instanceof DirectoryNode) {
                Filesystem::createDirectory($target . $id);
                $directory->render($node, $target . $id . '/index.html');
                $dashboard->render($node, $target . $id . '/dashboard.html');
            }
            else {
                $dir = dirname($target . $id);
                Filesystem::createDirectory($dir);
                $file->render($node, $target . $id);
            }
        }
        $this->copyFiles($target);
        $this->renderCss($target);
    }
    private function copyFiles(string $target) : void {
        $dir = $this->directory($target . '_css');
        copy($this->templatePath . 'css/bootstrap.min.css', $dir . 'bootstrap.min.css');
        copy($this->templatePath . 'css/nv.d3.min.css', $dir . 'nv.d3.min.css');
        copy($this->customCssFile
            ->path(), $dir . 'custom.css');
        copy($this->templatePath . 'css/octicons.css', $dir . 'octicons.css');
        $dir = $this->directory($target . '_icons');
        copy($this->templatePath . 'icons/file-code.svg', $dir . 'file-code.svg');
        copy($this->templatePath . 'icons/file-directory.svg', $dir . 'file-directory.svg');
        $dir = $this->directory($target . '_js');
        copy($this->templatePath . 'js/bootstrap.min.js', $dir . 'bootstrap.min.js');
        copy($this->templatePath . 'js/popper.min.js', $dir . 'popper.min.js');
        copy($this->templatePath . 'js/d3.min.js', $dir . 'd3.min.js');
        copy($this->templatePath . 'js/jquery.min.js', $dir . 'jquery.min.js');
        copy($this->templatePath . 'js/nv.d3.min.js', $dir . 'nv.d3.min.js');
        copy($this->templatePath . 'js/file.js', $dir . 'file.js');
    }
    private function renderCss(string $target) : void {
        $template = new Template($this->templatePath . 'css/style.css', '{{', '}}');
        $template->setVar([
            'success-low' => $this->colors
                ->successLow(),
            'success-medium' => $this->colors
                ->successMedium(),
            'success-high' => $this->colors
                ->successHigh(),
            'warning' => $this->colors
                ->warning(),
            'danger' => $this->colors
                ->danger(),
        ]);
        try {
            $template->renderTo($this->directory($target . '_css') . 'style.css');
        } catch (Exception $e) {
            throw new FileCouldNotBeWrittenException($e->getMessage(), $e->getCode(), $e);
        }
    }
    private function directory(string $directory) : string {
        if (!str_ends_with($directory, DIRECTORY_SEPARATOR)) {
            $directory .= DIRECTORY_SEPARATOR;
        }
        Filesystem::createDirectory($directory);
        return $directory;
    }

}

Members

Title Sort descending Modifiers Object type Summary
Facade::$colors private property
Facade::$customCssFile private property
Facade::$generator private property
Facade::$templatePath private property
Facade::$thresholds private property
Facade::copyFiles private function
Facade::directory private function
Facade::process public function
Facade::renderCss private function
Facade::__construct public function
RSS feed
Powered by Drupal