3 * This file is part of the PHP_CodeCoverage package.
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
12 * Generates an HTML report from an PHP_CodeCoverage object.
14 * @since Class available since Release 1.0.0
16 class PHP_CodeCoverage_Report_HTML
21 private $templatePath;
31 private $lowUpperBound;
36 private $highLowerBound;
41 * @param int $lowUpperBound
42 * @param int $highLowerBound
43 * @param string $generator
45 public function __construct($lowUpperBound = 50, $highLowerBound = 90, $generator = '')
47 $this->generator = $generator;
48 $this->highLowerBound = $highLowerBound;
49 $this->lowUpperBound = $lowUpperBound;
51 $this->templatePath = sprintf(
52 '%s%sHTML%sRenderer%sTemplate%s',
62 * @param PHP_CodeCoverage $coverage
63 * @param string $target
65 public function process(PHP_CodeCoverage $coverage, $target)
67 $target = $this->getDirectory($target);
68 $report = $coverage->getReport();
71 if (!isset($_SERVER['REQUEST_TIME'])) {
72 $_SERVER['REQUEST_TIME'] = time();
75 $date = date('D M j G:i:s T Y', $_SERVER['REQUEST_TIME']);
77 $dashboard = new PHP_CodeCoverage_Report_HTML_Renderer_Dashboard(
85 $directory = new PHP_CodeCoverage_Report_HTML_Renderer_Directory(
93 $file = new PHP_CodeCoverage_Report_HTML_Renderer_File(
101 $directory->render($report, $target . 'index.html');
102 $dashboard->render($report, $target . 'dashboard.html');
104 foreach ($report as $node) {
105 $id = $node->getId();
107 if ($node instanceof PHP_CodeCoverage_Report_Node_Directory) {
108 if (!file_exists($target . $id)) {
109 mkdir($target . $id, 0777, true);
112 $directory->render($node, $target . $id . '/index.html');
113 $dashboard->render($node, $target . $id . '/dashboard.html');
115 $dir = dirname($target . $id);
117 if (!file_exists($dir)) {
118 mkdir($dir, 0777, true);
121 $file->render($node, $target . $id . '.html');
125 $this->copyFiles($target);
129 * @param string $target
131 private function copyFiles($target)
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');
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');
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');
156 * @param string $directory
158 * @throws PHP_CodeCoverage_Exception
159 * @since Method available since Release 1.2.0
161 private function getDirectory($directory)
163 if (substr($directory, -1, 1) != DIRECTORY_SEPARATOR) {
164 $directory .= DIRECTORY_SEPARATOR;
167 if (is_dir($directory)) {
171 if (@mkdir($directory, 0777, true)) {
175 throw new PHP_CodeCoverage_Exception(
177 'Directory "%s" does not exist.',