comparison vendor/phpunit/php-code-coverage/src/CodeCoverage/Report/HTML.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2 /*
3 * This file is part of the PHP_CodeCoverage package.
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
11 /**
12 * Generates an HTML report from an PHP_CodeCoverage object.
13 *
14 * @since Class available since Release 1.0.0
15 */
16 class PHP_CodeCoverage_Report_HTML
17 {
18 /**
19 * @var string
20 */
21 private $templatePath;
22
23 /**
24 * @var string
25 */
26 private $generator;
27
28 /**
29 * @var int
30 */
31 private $lowUpperBound;
32
33 /**
34 * @var int
35 */
36 private $highLowerBound;
37
38 /**
39 * Constructor.
40 *
41 * @param int $lowUpperBound
42 * @param int $highLowerBound
43 * @param string $generator
44 */
45 public function __construct($lowUpperBound = 50, $highLowerBound = 90, $generator = '')
46 {
47 $this->generator = $generator;
48 $this->highLowerBound = $highLowerBound;
49 $this->lowUpperBound = $lowUpperBound;
50
51 $this->templatePath = sprintf(
52 '%s%sHTML%sRenderer%sTemplate%s',
53 dirname(__FILE__),
54 DIRECTORY_SEPARATOR,
55 DIRECTORY_SEPARATOR,
56 DIRECTORY_SEPARATOR,
57 DIRECTORY_SEPARATOR
58 );
59 }
60
61 /**
62 * @param PHP_CodeCoverage $coverage
63 * @param string $target
64 */
65 public function process(PHP_CodeCoverage $coverage, $target)
66 {
67 $target = $this->getDirectory($target);
68 $report = $coverage->getReport();
69 unset($coverage);
70
71 if (!isset($_SERVER['REQUEST_TIME'])) {
72 $_SERVER['REQUEST_TIME'] = time();
73 }
74
75 $date = date('D M j G:i:s T Y', $_SERVER['REQUEST_TIME']);
76
77 $dashboard = new PHP_CodeCoverage_Report_HTML_Renderer_Dashboard(
78 $this->templatePath,
79 $this->generator,
80 $date,
81 $this->lowUpperBound,
82 $this->highLowerBound
83 );
84
85 $directory = new PHP_CodeCoverage_Report_HTML_Renderer_Directory(
86 $this->templatePath,
87 $this->generator,
88 $date,
89 $this->lowUpperBound,
90 $this->highLowerBound
91 );
92
93 $file = new PHP_CodeCoverage_Report_HTML_Renderer_File(
94 $this->templatePath,
95 $this->generator,
96 $date,
97 $this->lowUpperBound,
98 $this->highLowerBound
99 );
100
101 $directory->render($report, $target . 'index.html');
102 $dashboard->render($report, $target . 'dashboard.html');
103
104 foreach ($report as $node) {
105 $id = $node->getId();
106
107 if ($node instanceof PHP_CodeCoverage_Report_Node_Directory) {
108 if (!file_exists($target . $id)) {
109 mkdir($target . $id, 0777, true);
110 }
111
112 $directory->render($node, $target . $id . '/index.html');
113 $dashboard->render($node, $target . $id . '/dashboard.html');
114 } else {
115 $dir = dirname($target . $id);
116
117 if (!file_exists($dir)) {
118 mkdir($dir, 0777, true);
119 }
120
121 $file->render($node, $target . $id . '.html');
122 }
123 }
124
125 $this->copyFiles($target);
126 }
127
128 /**
129 * @param string $target
130 */
131 private function copyFiles($target)
132 {
133 $dir = $this->getDirectory($target . 'css');
134 copy($this->templatePath . 'css/bootstrap.min.css', $dir . 'bootstrap.min.css');
135 copy($this->templatePath . 'css/nv.d3.min.css', $dir . 'nv.d3.min.css');
136 copy($this->templatePath . 'css/style.css', $dir . 'style.css');
137
138 $dir = $this->getDirectory($target . 'fonts');
139 copy($this->templatePath . 'fonts/glyphicons-halflings-regular.eot', $dir . 'glyphicons-halflings-regular.eot');
140 copy($this->templatePath . 'fonts/glyphicons-halflings-regular.svg', $dir . 'glyphicons-halflings-regular.svg');
141 copy($this->templatePath . 'fonts/glyphicons-halflings-regular.ttf', $dir . 'glyphicons-halflings-regular.ttf');
142 copy($this->templatePath . 'fonts/glyphicons-halflings-regular.woff', $dir . 'glyphicons-halflings-regular.woff');
143 copy($this->templatePath . 'fonts/glyphicons-halflings-regular.woff2', $dir . 'glyphicons-halflings-regular.woff2');
144
145 $dir = $this->getDirectory($target . 'js');
146 copy($this->templatePath . 'js/bootstrap.min.js', $dir . 'bootstrap.min.js');
147 copy($this->templatePath . 'js/d3.min.js', $dir . 'd3.min.js');
148 copy($this->templatePath . 'js/holder.min.js', $dir . 'holder.min.js');
149 copy($this->templatePath . 'js/html5shiv.min.js', $dir . 'html5shiv.min.js');
150 copy($this->templatePath . 'js/jquery.min.js', $dir . 'jquery.min.js');
151 copy($this->templatePath . 'js/nv.d3.min.js', $dir . 'nv.d3.min.js');
152 copy($this->templatePath . 'js/respond.min.js', $dir . 'respond.min.js');
153 }
154
155 /**
156 * @param string $directory
157 * @return string
158 * @throws PHP_CodeCoverage_Exception
159 * @since Method available since Release 1.2.0
160 */
161 private function getDirectory($directory)
162 {
163 if (substr($directory, -1, 1) != DIRECTORY_SEPARATOR) {
164 $directory .= DIRECTORY_SEPARATOR;
165 }
166
167 if (is_dir($directory)) {
168 return $directory;
169 }
170
171 if (@mkdir($directory, 0777, true)) {
172 return $directory;
173 }
174
175 throw new PHP_CodeCoverage_Exception(
176 sprintf(
177 'Directory "%s" does not exist.',
178 $directory
179 )
180 );
181 }
182 }