comparison vendor/phpunit/php-code-coverage/src/Node/AbstractNode.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents
children
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
1 <?php
2 /*
3 * This file is part of the php-code-coverage 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 namespace SebastianBergmann\CodeCoverage\Node;
12
13 use SebastianBergmann\CodeCoverage\Util;
14
15 /**
16 * Base class for nodes in the code coverage information tree.
17 */
18 abstract class AbstractNode implements \Countable
19 {
20 /**
21 * @var string
22 */
23 private $name;
24
25 /**
26 * @var string
27 */
28 private $path;
29
30 /**
31 * @var array
32 */
33 private $pathArray;
34
35 /**
36 * @var AbstractNode
37 */
38 private $parent;
39
40 /**
41 * @var string
42 */
43 private $id;
44
45 /**
46 * Constructor.
47 *
48 * @param string $name
49 * @param AbstractNode $parent
50 */
51 public function __construct($name, self $parent = null)
52 {
53 if (\substr($name, -1) == '/') {
54 $name = \substr($name, 0, -1);
55 }
56
57 $this->name = $name;
58 $this->parent = $parent;
59 }
60
61 /**
62 * @return string
63 */
64 public function getName()
65 {
66 return $this->name;
67 }
68
69 /**
70 * @return string
71 */
72 public function getId()
73 {
74 if ($this->id === null) {
75 $parent = $this->getParent();
76
77 if ($parent === null) {
78 $this->id = 'index';
79 } else {
80 $parentId = $parent->getId();
81
82 if ($parentId == 'index') {
83 $this->id = \str_replace(':', '_', $this->name);
84 } else {
85 $this->id = $parentId . '/' . $this->name;
86 }
87 }
88 }
89
90 return $this->id;
91 }
92
93 /**
94 * @return string
95 */
96 public function getPath()
97 {
98 if ($this->path === null) {
99 if ($this->parent === null || $this->parent->getPath() === null || $this->parent->getPath() === false) {
100 $this->path = $this->name;
101 } else {
102 $this->path = $this->parent->getPath() . '/' . $this->name;
103 }
104 }
105
106 return $this->path;
107 }
108
109 /**
110 * @return array
111 */
112 public function getPathAsArray()
113 {
114 if ($this->pathArray === null) {
115 if ($this->parent === null) {
116 $this->pathArray = [];
117 } else {
118 $this->pathArray = $this->parent->getPathAsArray();
119 }
120
121 $this->pathArray[] = $this;
122 }
123
124 return $this->pathArray;
125 }
126
127 /**
128 * @return AbstractNode
129 */
130 public function getParent()
131 {
132 return $this->parent;
133 }
134
135 /**
136 * Returns the percentage of classes that has been tested.
137 *
138 * @param bool $asString
139 *
140 * @return int
141 */
142 public function getTestedClassesPercent($asString = true)
143 {
144 return Util::percent(
145 $this->getNumTestedClasses(),
146 $this->getNumClasses(),
147 $asString
148 );
149 }
150
151 /**
152 * Returns the percentage of traits that has been tested.
153 *
154 * @param bool $asString
155 *
156 * @return int
157 */
158 public function getTestedTraitsPercent($asString = true)
159 {
160 return Util::percent(
161 $this->getNumTestedTraits(),
162 $this->getNumTraits(),
163 $asString
164 );
165 }
166
167 /**
168 * Returns the percentage of classes and traits that has been tested.
169 *
170 * @param bool $asString
171 *
172 * @return int
173 */
174 public function getTestedClassesAndTraitsPercent($asString = true)
175 {
176 return Util::percent(
177 $this->getNumTestedClassesAndTraits(),
178 $this->getNumClassesAndTraits(),
179 $asString
180 );
181 }
182
183 /**
184 * Returns the percentage of functions that has been tested.
185 *
186 * @param bool $asString
187 *
188 * @return int
189 */
190 public function getTestedFunctionsPercent($asString = true)
191 {
192 return Util::percent(
193 $this->getNumTestedFunctions(),
194 $this->getNumFunctions(),
195 $asString
196 );
197 }
198
199 /**
200 * Returns the percentage of methods that has been tested.
201 *
202 * @param bool $asString
203 *
204 * @return int
205 */
206 public function getTestedMethodsPercent($asString = true)
207 {
208 return Util::percent(
209 $this->getNumTestedMethods(),
210 $this->getNumMethods(),
211 $asString
212 );
213 }
214
215 /**
216 * Returns the percentage of functions and methods that has been tested.
217 *
218 * @param bool $asString
219 *
220 * @return int
221 */
222 public function getTestedFunctionsAndMethodsPercent($asString = true)
223 {
224 return Util::percent(
225 $this->getNumTestedFunctionsAndMethods(),
226 $this->getNumFunctionsAndMethods(),
227 $asString
228 );
229 }
230
231 /**
232 * Returns the percentage of executed lines.
233 *
234 * @param bool $asString
235 *
236 * @return int
237 */
238 public function getLineExecutedPercent($asString = true)
239 {
240 return Util::percent(
241 $this->getNumExecutedLines(),
242 $this->getNumExecutableLines(),
243 $asString
244 );
245 }
246
247 /**
248 * Returns the number of classes and traits.
249 *
250 * @return int
251 */
252 public function getNumClassesAndTraits()
253 {
254 return $this->getNumClasses() + $this->getNumTraits();
255 }
256
257 /**
258 * Returns the number of tested classes and traits.
259 *
260 * @return int
261 */
262 public function getNumTestedClassesAndTraits()
263 {
264 return $this->getNumTestedClasses() + $this->getNumTestedTraits();
265 }
266
267 /**
268 * Returns the classes and traits of this node.
269 *
270 * @return array
271 */
272 public function getClassesAndTraits()
273 {
274 return \array_merge($this->getClasses(), $this->getTraits());
275 }
276
277 /**
278 * Returns the number of functions and methods.
279 *
280 * @return int
281 */
282 public function getNumFunctionsAndMethods()
283 {
284 return $this->getNumFunctions() + $this->getNumMethods();
285 }
286
287 /**
288 * Returns the number of tested functions and methods.
289 *
290 * @return int
291 */
292 public function getNumTestedFunctionsAndMethods()
293 {
294 return $this->getNumTestedFunctions() + $this->getNumTestedMethods();
295 }
296
297 /**
298 * Returns the functions and methods of this node.
299 *
300 * @return array
301 */
302 public function getFunctionsAndMethods()
303 {
304 return \array_merge($this->getFunctions(), $this->getMethods());
305 }
306
307 /**
308 * Returns the classes of this node.
309 *
310 * @return array
311 */
312 abstract public function getClasses();
313
314 /**
315 * Returns the traits of this node.
316 *
317 * @return array
318 */
319 abstract public function getTraits();
320
321 /**
322 * Returns the functions of this node.
323 *
324 * @return array
325 */
326 abstract public function getFunctions();
327
328 /**
329 * Returns the LOC/CLOC/NCLOC of this node.
330 *
331 * @return array
332 */
333 abstract public function getLinesOfCode();
334
335 /**
336 * Returns the number of executable lines.
337 *
338 * @return int
339 */
340 abstract public function getNumExecutableLines();
341
342 /**
343 * Returns the number of executed lines.
344 *
345 * @return int
346 */
347 abstract public function getNumExecutedLines();
348
349 /**
350 * Returns the number of classes.
351 *
352 * @return int
353 */
354 abstract public function getNumClasses();
355
356 /**
357 * Returns the number of tested classes.
358 *
359 * @return int
360 */
361 abstract public function getNumTestedClasses();
362
363 /**
364 * Returns the number of traits.
365 *
366 * @return int
367 */
368 abstract public function getNumTraits();
369
370 /**
371 * Returns the number of tested traits.
372 *
373 * @return int
374 */
375 abstract public function getNumTestedTraits();
376
377 /**
378 * Returns the number of methods.
379 *
380 * @return int
381 */
382 abstract public function getNumMethods();
383
384 /**
385 * Returns the number of tested methods.
386 *
387 * @return int
388 */
389 abstract public function getNumTestedMethods();
390
391 /**
392 * Returns the number of functions.
393 *
394 * @return int
395 */
396 abstract public function getNumFunctions();
397
398 /**
399 * Returns the number of tested functions.
400 *
401 * @return int
402 */
403 abstract public function getNumTestedFunctions();
404 }