5 * Copyright (c) 2009-2011, Sebastian Bergmann <sb@sebastian-bergmann.de>.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
20 * * Neither the name of Sebastian Bergmann nor the names of his
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
38 * @package CodeCoverage
39 * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
40 * @copyright 2009-2011 Sebastian Bergmann <sb@sebastian-bergmann.de>
41 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
42 * @link http://github.com/sebastianbergmann/php-code-coverage
43 * @since File available since Release 1.1.0
47 * Base class for PHP_CodeCoverage_Report_Node renderers.
50 * @package CodeCoverage
51 * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
52 * @copyright 2009-2011 Sebastian Bergmann <sb@sebastian-bergmann.de>
53 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
54 * @version Release: 1.1.1
55 * @link http://github.com/sebastianbergmann/php-code-coverage
56 * @since Class available since Release 1.1.0
58 abstract class PHP_CodeCoverage_Report_HTML_Renderer
63 protected $templatePath;
83 protected $lowUpperBound;
88 protected $highLowerBound;
93 * @param string $templatePath
94 * @param string $charset
95 * @param string $generator
97 * @param integer $lowUpperBound
98 * @param integer $highLowerBound
100 public function __construct($templatePath, $charset, $generator, $date, $lowUpperBound, $highLowerBound)
102 $this->templatePath = $templatePath;
103 $this->charset = $charset;
104 $this->generator = $generator;
106 $this->lowUpperBound = $lowUpperBound;
107 $this->highLowerBound = $highLowerBound;
111 * @param integer $percent
114 protected function getColorLevel($percent)
116 if ($percent < $this->lowUpperBound) {
117 $color = 'scarlet_red';
121 else if ($percent >= $this->lowUpperBound &&
122 $percent < $this->highLowerBound) {
128 $color = 'chameleon';
132 return array($color, $level);
136 * @param Text_Template $template
140 protected function renderItemTemplate(Text_Template $template, array $data)
142 if (isset($data['numClasses']) && $data['numClasses'] > 0) {
143 list($classesColor, $classesLevel) = $this->getColorLevel(
144 $data['testedClassesPercent']
147 $classesNumber = $data['numTestedClasses'] . ' / ' .
150 $classesColor = 'snow';
151 $classesLevel = 'None';
152 $classesNumber = ' ';
155 if ($data['numMethods'] > 0) {
156 list($methodsColor, $methodsLevel) = $this->getColorLevel(
157 $data['testedMethodsPercent']
160 $methodsNumber = $data['numTestedMethods'] . ' / ' .
163 $methodsColor = 'snow';
164 $methodsLevel = 'None';
165 $methodsNumber = ' ';
168 list($linesColor, $linesLevel) = $this->getColorLevel(
169 $data['linesExecutedPercent']
174 'itemClass' => isset($data['itemClass']) ? $data['itemClass'] : '',
175 'icon' => isset($data['icon']) ? $data['icon'] : '',
176 'crap' => isset($data['crap']) ? $data['crap'] : '',
177 'name' => $data['name'],
178 'lines_color' => $linesColor,
179 'lines_executed_width' => $data['linesExecutedPercent'],
180 'lines_not_executed_width' => 100 - $data['linesExecutedPercent'],
181 'lines_executed_percent' => $data['linesExecutedPercentAsString'],
182 'lines_level' => $linesLevel,
183 'num_executed_lines' => $data['numExecutedLines'],
184 'num_executable_lines' => $data['numExecutableLines'],
185 'methods_color' => $methodsColor,
186 'methods_tested_width' => $data['testedMethodsPercent'],
187 'methods_not_tested_width' => 100 - $data['testedMethodsPercent'],
188 'methods_tested_percent' => $data['testedMethodsPercentAsString'],
189 'methods_level' => $methodsLevel,
190 'methods_number' => $methodsNumber,
191 'classes_color' => $classesColor,
192 'classes_tested_width' => isset($data['testedClassesPercent']) ? $data['testedClassesPercent'] : '',
193 'classes_not_tested_width' => isset($data['testedClassesPercent']) ? 100 - $data['testedClassesPercent'] : '',
194 'classes_tested_percent' => isset($data['testedClassesPercentAsString']) ? $data['testedClassesPercentAsString'] : '',
195 'classes_level' => $classesLevel,
196 'classes_number' => $classesNumber
200 return $template->render();
204 * @param Text_Template $template
205 * @param string $title
206 * @param PHP_CodeCoverage_Report_Node $node
208 protected function setCommonTemplateVariables(Text_Template $template, $title, PHP_CodeCoverage_Report_Node $node = NULL)
212 if ($node !== NULL) {
213 $path = $node->getPathAsArray();
215 foreach ($path as $step) {
217 '%s<a href="%s.html">%s</a>',
218 !empty($link) ? '/' : '',
229 'charset' => $this->charset,
230 'date' => $this->date,
231 'version' => '1.1.1',
232 'php_version' => PHP_VERSION,
233 'generator' => $this->generator,
234 'low_upper_bound' => $this->lowUpperBound,
235 'high_lower_bound' => $this->highLowerBound