Chris@0
|
1 <?php
|
Chris@0
|
2 /*
|
Chris@0
|
3 * This file is part of the PHP_CodeCoverage package.
|
Chris@0
|
4 *
|
Chris@0
|
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
|
Chris@0
|
6 *
|
Chris@0
|
7 * For the full copyright and license information, please view the LICENSE
|
Chris@0
|
8 * file that was distributed with this source code.
|
Chris@0
|
9 */
|
Chris@0
|
10
|
Chris@0
|
11 /**
|
Chris@0
|
12 * Base class for nodes in the code coverage information tree.
|
Chris@0
|
13 *
|
Chris@0
|
14 * @since Class available since Release 1.1.0
|
Chris@0
|
15 */
|
Chris@0
|
16 abstract class PHP_CodeCoverage_Report_Node implements Countable
|
Chris@0
|
17 {
|
Chris@0
|
18 /**
|
Chris@0
|
19 * @var string
|
Chris@0
|
20 */
|
Chris@0
|
21 protected $name;
|
Chris@0
|
22
|
Chris@0
|
23 /**
|
Chris@0
|
24 * @var string
|
Chris@0
|
25 */
|
Chris@0
|
26 protected $path;
|
Chris@0
|
27
|
Chris@0
|
28 /**
|
Chris@0
|
29 * @var array
|
Chris@0
|
30 */
|
Chris@0
|
31 protected $pathArray;
|
Chris@0
|
32
|
Chris@0
|
33 /**
|
Chris@0
|
34 * @var PHP_CodeCoverage_Report_Node
|
Chris@0
|
35 */
|
Chris@0
|
36 protected $parent;
|
Chris@0
|
37
|
Chris@0
|
38 /**
|
Chris@0
|
39 * @var string
|
Chris@0
|
40 */
|
Chris@0
|
41 protected $id;
|
Chris@0
|
42
|
Chris@0
|
43 /**
|
Chris@0
|
44 * Constructor.
|
Chris@0
|
45 *
|
Chris@0
|
46 * @param string $name
|
Chris@0
|
47 * @param PHP_CodeCoverage_Report_Node $parent
|
Chris@0
|
48 */
|
Chris@0
|
49 public function __construct($name, PHP_CodeCoverage_Report_Node $parent = null)
|
Chris@0
|
50 {
|
Chris@0
|
51 if (substr($name, -1) == '/') {
|
Chris@0
|
52 $name = substr($name, 0, -1);
|
Chris@0
|
53 }
|
Chris@0
|
54
|
Chris@0
|
55 $this->name = $name;
|
Chris@0
|
56 $this->parent = $parent;
|
Chris@0
|
57 }
|
Chris@0
|
58
|
Chris@0
|
59 /**
|
Chris@0
|
60 * @return string
|
Chris@0
|
61 */
|
Chris@0
|
62 public function getName()
|
Chris@0
|
63 {
|
Chris@0
|
64 return $this->name;
|
Chris@0
|
65 }
|
Chris@0
|
66
|
Chris@0
|
67 /**
|
Chris@0
|
68 * @return string
|
Chris@0
|
69 */
|
Chris@0
|
70 public function getId()
|
Chris@0
|
71 {
|
Chris@0
|
72 if ($this->id === null) {
|
Chris@0
|
73 $parent = $this->getParent();
|
Chris@0
|
74
|
Chris@0
|
75 if ($parent === null) {
|
Chris@0
|
76 $this->id = 'index';
|
Chris@0
|
77 } else {
|
Chris@0
|
78 $parentId = $parent->getId();
|
Chris@0
|
79
|
Chris@0
|
80 if ($parentId == 'index') {
|
Chris@0
|
81 $this->id = str_replace(':', '_', $this->name);
|
Chris@0
|
82 } else {
|
Chris@0
|
83 $this->id = $parentId . '/' . $this->name;
|
Chris@0
|
84 }
|
Chris@0
|
85 }
|
Chris@0
|
86 }
|
Chris@0
|
87
|
Chris@0
|
88 return $this->id;
|
Chris@0
|
89 }
|
Chris@0
|
90
|
Chris@0
|
91 /**
|
Chris@0
|
92 * @return string
|
Chris@0
|
93 */
|
Chris@0
|
94 public function getPath()
|
Chris@0
|
95 {
|
Chris@0
|
96 if ($this->path === null) {
|
Chris@0
|
97 if ($this->parent === null || $this->parent->getPath() === null || $this->parent->getPath() === false) {
|
Chris@0
|
98 $this->path = $this->name;
|
Chris@0
|
99 } else {
|
Chris@0
|
100 $this->path = $this->parent->getPath() . '/' . $this->name;
|
Chris@0
|
101 }
|
Chris@0
|
102 }
|
Chris@0
|
103
|
Chris@0
|
104 return $this->path;
|
Chris@0
|
105 }
|
Chris@0
|
106
|
Chris@0
|
107 /**
|
Chris@0
|
108 * @return array
|
Chris@0
|
109 */
|
Chris@0
|
110 public function getPathAsArray()
|
Chris@0
|
111 {
|
Chris@0
|
112 if ($this->pathArray === null) {
|
Chris@0
|
113 if ($this->parent === null) {
|
Chris@0
|
114 $this->pathArray = array();
|
Chris@0
|
115 } else {
|
Chris@0
|
116 $this->pathArray = $this->parent->getPathAsArray();
|
Chris@0
|
117 }
|
Chris@0
|
118
|
Chris@0
|
119 $this->pathArray[] = $this;
|
Chris@0
|
120 }
|
Chris@0
|
121
|
Chris@0
|
122 return $this->pathArray;
|
Chris@0
|
123 }
|
Chris@0
|
124
|
Chris@0
|
125 /**
|
Chris@0
|
126 * @return PHP_CodeCoverage_Report_Node
|
Chris@0
|
127 */
|
Chris@0
|
128 public function getParent()
|
Chris@0
|
129 {
|
Chris@0
|
130 return $this->parent;
|
Chris@0
|
131 }
|
Chris@0
|
132
|
Chris@0
|
133 /**
|
Chris@0
|
134 * Returns the percentage of classes that has been tested.
|
Chris@0
|
135 *
|
Chris@0
|
136 * @param bool $asString
|
Chris@0
|
137 * @return int
|
Chris@0
|
138 */
|
Chris@0
|
139 public function getTestedClassesPercent($asString = true)
|
Chris@0
|
140 {
|
Chris@0
|
141 return PHP_CodeCoverage_Util::percent(
|
Chris@0
|
142 $this->getNumTestedClasses(),
|
Chris@0
|
143 $this->getNumClasses(),
|
Chris@0
|
144 $asString
|
Chris@0
|
145 );
|
Chris@0
|
146 }
|
Chris@0
|
147
|
Chris@0
|
148 /**
|
Chris@0
|
149 * Returns the percentage of traits that has been tested.
|
Chris@0
|
150 *
|
Chris@0
|
151 * @param bool $asString
|
Chris@0
|
152 * @return int
|
Chris@0
|
153 */
|
Chris@0
|
154 public function getTestedTraitsPercent($asString = true)
|
Chris@0
|
155 {
|
Chris@0
|
156 return PHP_CodeCoverage_Util::percent(
|
Chris@0
|
157 $this->getNumTestedTraits(),
|
Chris@0
|
158 $this->getNumTraits(),
|
Chris@0
|
159 $asString
|
Chris@0
|
160 );
|
Chris@0
|
161 }
|
Chris@0
|
162
|
Chris@0
|
163 /**
|
Chris@0
|
164 * Returns the percentage of traits that has been tested.
|
Chris@0
|
165 *
|
Chris@0
|
166 * @param bool $asString
|
Chris@0
|
167 * @return int
|
Chris@0
|
168 * @since Method available since Release 1.2.0
|
Chris@0
|
169 */
|
Chris@0
|
170 public function getTestedClassesAndTraitsPercent($asString = true)
|
Chris@0
|
171 {
|
Chris@0
|
172 return PHP_CodeCoverage_Util::percent(
|
Chris@0
|
173 $this->getNumTestedClassesAndTraits(),
|
Chris@0
|
174 $this->getNumClassesAndTraits(),
|
Chris@0
|
175 $asString
|
Chris@0
|
176 );
|
Chris@0
|
177 }
|
Chris@0
|
178
|
Chris@0
|
179 /**
|
Chris@0
|
180 * Returns the percentage of methods that has been tested.
|
Chris@0
|
181 *
|
Chris@0
|
182 * @param bool $asString
|
Chris@0
|
183 * @return int
|
Chris@0
|
184 */
|
Chris@0
|
185 public function getTestedMethodsPercent($asString = true)
|
Chris@0
|
186 {
|
Chris@0
|
187 return PHP_CodeCoverage_Util::percent(
|
Chris@0
|
188 $this->getNumTestedMethods(),
|
Chris@0
|
189 $this->getNumMethods(),
|
Chris@0
|
190 $asString
|
Chris@0
|
191 );
|
Chris@0
|
192 }
|
Chris@0
|
193
|
Chris@0
|
194 /**
|
Chris@0
|
195 * Returns the percentage of executed lines.
|
Chris@0
|
196 *
|
Chris@0
|
197 * @param bool $asString
|
Chris@0
|
198 * @return int
|
Chris@0
|
199 */
|
Chris@0
|
200 public function getLineExecutedPercent($asString = true)
|
Chris@0
|
201 {
|
Chris@0
|
202 return PHP_CodeCoverage_Util::percent(
|
Chris@0
|
203 $this->getNumExecutedLines(),
|
Chris@0
|
204 $this->getNumExecutableLines(),
|
Chris@0
|
205 $asString
|
Chris@0
|
206 );
|
Chris@0
|
207 }
|
Chris@0
|
208
|
Chris@0
|
209 /**
|
Chris@0
|
210 * Returns the number of classes and traits.
|
Chris@0
|
211 *
|
Chris@0
|
212 * @return int
|
Chris@0
|
213 * @since Method available since Release 1.2.0
|
Chris@0
|
214 */
|
Chris@0
|
215 public function getNumClassesAndTraits()
|
Chris@0
|
216 {
|
Chris@0
|
217 return $this->getNumClasses() + $this->getNumTraits();
|
Chris@0
|
218 }
|
Chris@0
|
219
|
Chris@0
|
220 /**
|
Chris@0
|
221 * Returns the number of tested classes and traits.
|
Chris@0
|
222 *
|
Chris@0
|
223 * @return int
|
Chris@0
|
224 * @since Method available since Release 1.2.0
|
Chris@0
|
225 */
|
Chris@0
|
226 public function getNumTestedClassesAndTraits()
|
Chris@0
|
227 {
|
Chris@0
|
228 return $this->getNumTestedClasses() + $this->getNumTestedTraits();
|
Chris@0
|
229 }
|
Chris@0
|
230
|
Chris@0
|
231 /**
|
Chris@0
|
232 * Returns the classes and traits of this node.
|
Chris@0
|
233 *
|
Chris@0
|
234 * @return array
|
Chris@0
|
235 * @since Method available since Release 1.2.0
|
Chris@0
|
236 */
|
Chris@0
|
237 public function getClassesAndTraits()
|
Chris@0
|
238 {
|
Chris@0
|
239 return array_merge($this->getClasses(), $this->getTraits());
|
Chris@0
|
240 }
|
Chris@0
|
241
|
Chris@0
|
242 /**
|
Chris@0
|
243 * Returns the classes of this node.
|
Chris@0
|
244 *
|
Chris@0
|
245 * @return array
|
Chris@0
|
246 */
|
Chris@0
|
247 abstract public function getClasses();
|
Chris@0
|
248
|
Chris@0
|
249 /**
|
Chris@0
|
250 * Returns the traits of this node.
|
Chris@0
|
251 *
|
Chris@0
|
252 * @return array
|
Chris@0
|
253 */
|
Chris@0
|
254 abstract public function getTraits();
|
Chris@0
|
255
|
Chris@0
|
256 /**
|
Chris@0
|
257 * Returns the functions of this node.
|
Chris@0
|
258 *
|
Chris@0
|
259 * @return array
|
Chris@0
|
260 */
|
Chris@0
|
261 abstract public function getFunctions();
|
Chris@0
|
262
|
Chris@0
|
263 /**
|
Chris@0
|
264 * Returns the LOC/CLOC/NCLOC of this node.
|
Chris@0
|
265 *
|
Chris@0
|
266 * @return array
|
Chris@0
|
267 */
|
Chris@0
|
268 abstract public function getLinesOfCode();
|
Chris@0
|
269
|
Chris@0
|
270 /**
|
Chris@0
|
271 * Returns the number of executable lines.
|
Chris@0
|
272 *
|
Chris@0
|
273 * @return int
|
Chris@0
|
274 */
|
Chris@0
|
275 abstract public function getNumExecutableLines();
|
Chris@0
|
276
|
Chris@0
|
277 /**
|
Chris@0
|
278 * Returns the number of executed lines.
|
Chris@0
|
279 *
|
Chris@0
|
280 * @return int
|
Chris@0
|
281 */
|
Chris@0
|
282 abstract public function getNumExecutedLines();
|
Chris@0
|
283
|
Chris@0
|
284 /**
|
Chris@0
|
285 * Returns the number of classes.
|
Chris@0
|
286 *
|
Chris@0
|
287 * @return int
|
Chris@0
|
288 */
|
Chris@0
|
289 abstract public function getNumClasses();
|
Chris@0
|
290
|
Chris@0
|
291 /**
|
Chris@0
|
292 * Returns the number of tested classes.
|
Chris@0
|
293 *
|
Chris@0
|
294 * @return int
|
Chris@0
|
295 */
|
Chris@0
|
296 abstract public function getNumTestedClasses();
|
Chris@0
|
297
|
Chris@0
|
298 /**
|
Chris@0
|
299 * Returns the number of traits.
|
Chris@0
|
300 *
|
Chris@0
|
301 * @return int
|
Chris@0
|
302 */
|
Chris@0
|
303 abstract public function getNumTraits();
|
Chris@0
|
304
|
Chris@0
|
305 /**
|
Chris@0
|
306 * Returns the number of tested traits.
|
Chris@0
|
307 *
|
Chris@0
|
308 * @return int
|
Chris@0
|
309 */
|
Chris@0
|
310 abstract public function getNumTestedTraits();
|
Chris@0
|
311
|
Chris@0
|
312 /**
|
Chris@0
|
313 * Returns the number of methods.
|
Chris@0
|
314 *
|
Chris@0
|
315 * @return int
|
Chris@0
|
316 */
|
Chris@0
|
317 abstract public function getNumMethods();
|
Chris@0
|
318
|
Chris@0
|
319 /**
|
Chris@0
|
320 * Returns the number of tested methods.
|
Chris@0
|
321 *
|
Chris@0
|
322 * @return int
|
Chris@0
|
323 */
|
Chris@0
|
324 abstract public function getNumTestedMethods();
|
Chris@0
|
325
|
Chris@0
|
326 /**
|
Chris@0
|
327 * Returns the number of functions.
|
Chris@0
|
328 *
|
Chris@0
|
329 * @return int
|
Chris@0
|
330 */
|
Chris@0
|
331 abstract public function getNumFunctions();
|
Chris@0
|
332
|
Chris@0
|
333 /**
|
Chris@0
|
334 * Returns the number of tested functions.
|
Chris@0
|
335 *
|
Chris@0
|
336 * @return int
|
Chris@0
|
337 */
|
Chris@0
|
338 abstract public function getNumTestedFunctions();
|
Chris@0
|
339 }
|