Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of phpunit/php-code-coverage.
4
 *
5
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace SebastianBergmann\CodeCoverage\Report\Html;
11
 
12
use const DIRECTORY_SEPARATOR;
13
use function copy;
14
use function date;
15
use function dirname;
16
use function substr;
17
use SebastianBergmann\CodeCoverage\CodeCoverage;
18
use SebastianBergmann\CodeCoverage\InvalidArgumentException;
19
use SebastianBergmann\CodeCoverage\Node\Directory as DirectoryNode;
20
use SebastianBergmann\CodeCoverage\Util\Filesystem;
21
 
22
final class Facade
23
{
24
    /**
25
     * @var string
26
     */
27
    private $templatePath;
28
 
29
    /**
30
     * @var string
31
     */
32
    private $generator;
33
 
34
    /**
35
     * @var int
36
     */
37
    private $lowUpperBound;
38
 
39
    /**
40
     * @var int
41
     */
42
    private $highLowerBound;
43
 
44
    public function __construct(int $lowUpperBound = 50, int $highLowerBound = 90, string $generator = '')
45
    {
46
        if ($lowUpperBound > $highLowerBound) {
47
            throw new InvalidArgumentException(
48
                '$lowUpperBound must not be larger than $highLowerBound'
49
            );
50
        }
51
 
52
        $this->generator      = $generator;
53
        $this->highLowerBound = $highLowerBound;
54
        $this->lowUpperBound  = $lowUpperBound;
55
        $this->templatePath   = __DIR__ . '/Renderer/Template/';
56
    }
57
 
58
    public function process(CodeCoverage $coverage, string $target): void
59
    {
60
        $target = $this->directory($target);
61
        $report = $coverage->getReport();
62
        $date   = date('D M j G:i:s T Y');
63
 
64
        $dashboard = new Dashboard(
65
            $this->templatePath,
66
            $this->generator,
67
            $date,
68
            $this->lowUpperBound,
69
            $this->highLowerBound,
70
            $coverage->collectsBranchAndPathCoverage()
71
        );
72
 
73
        $directory = new Directory(
74
            $this->templatePath,
75
            $this->generator,
76
            $date,
77
            $this->lowUpperBound,
78
            $this->highLowerBound,
79
            $coverage->collectsBranchAndPathCoverage()
80
        );
81
 
82
        $file = new File(
83
            $this->templatePath,
84
            $this->generator,
85
            $date,
86
            $this->lowUpperBound,
87
            $this->highLowerBound,
88
            $coverage->collectsBranchAndPathCoverage()
89
        );
90
 
91
        $directory->render($report, $target . 'index.html');
92
        $dashboard->render($report, $target . 'dashboard.html');
93
 
94
        foreach ($report as $node) {
95
            $id = $node->id();
96
 
97
            if ($node instanceof DirectoryNode) {
98
                Filesystem::createDirectory($target . $id);
99
 
100
                $directory->render($node, $target . $id . '/index.html');
101
                $dashboard->render($node, $target . $id . '/dashboard.html');
102
            } else {
103
                $dir = dirname($target . $id);
104
 
105
                Filesystem::createDirectory($dir);
106
 
107
                $file->render($node, $target . $id);
108
            }
109
        }
110
 
111
        $this->copyFiles($target);
112
    }
113
 
114
    private function copyFiles(string $target): void
115
    {
116
        $dir = $this->directory($target . '_css');
117
 
118
        copy($this->templatePath . 'css/bootstrap.min.css', $dir . 'bootstrap.min.css');
119
        copy($this->templatePath . 'css/nv.d3.min.css', $dir . 'nv.d3.min.css');
120
        copy($this->templatePath . 'css/style.css', $dir . 'style.css');
121
        copy($this->templatePath . 'css/custom.css', $dir . 'custom.css');
122
        copy($this->templatePath . 'css/octicons.css', $dir . 'octicons.css');
123
 
124
        $dir = $this->directory($target . '_icons');
125
        copy($this->templatePath . 'icons/file-code.svg', $dir . 'file-code.svg');
126
        copy($this->templatePath . 'icons/file-directory.svg', $dir . 'file-directory.svg');
127
 
128
        $dir = $this->directory($target . '_js');
129
        copy($this->templatePath . 'js/bootstrap.min.js', $dir . 'bootstrap.min.js');
130
        copy($this->templatePath . 'js/popper.min.js', $dir . 'popper.min.js');
131
        copy($this->templatePath . 'js/d3.min.js', $dir . 'd3.min.js');
132
        copy($this->templatePath . 'js/jquery.min.js', $dir . 'jquery.min.js');
133
        copy($this->templatePath . 'js/nv.d3.min.js', $dir . 'nv.d3.min.js');
134
        copy($this->templatePath . 'js/file.js', $dir . 'file.js');
135
    }
136
 
137
    private function directory(string $directory): string
138
    {
139
        if (substr($directory, -1, 1) != DIRECTORY_SEPARATOR) {
140
            $directory .= DIRECTORY_SEPARATOR;
141
        }
142
 
143
        Filesystem::createDirectory($directory);
144
 
145
        return $directory;
146
    }
147
}