Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of phpunit/php-code-coverage.
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
namespace SebastianBergmann\CodeCoverage\Node;
11
 
12
use function array_merge;
13
use function count;
14
use IteratorAggregate;
15
use RecursiveIteratorIterator;
16
 
17
/**
18
 * @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
19
 */
20
final class Directory extends AbstractNode implements IteratorAggregate
21
{
22
    /**
23
     * @var AbstractNode[]
24
     */
25
    private $children = [];
26
 
27
    /**
28
     * @var Directory[]
29
     */
30
    private $directories = [];
31
 
32
    /**
33
     * @var File[]
34
     */
35
    private $files = [];
36
 
37
    /**
38
     * @var array
39
     */
40
    private $classes;
41
 
42
    /**
43
     * @var array
44
     */
45
    private $traits;
46
 
47
    /**
48
     * @var array
49
     */
50
    private $functions;
51
 
52
    /**
53
     * @psalm-var null|array{linesOfCode: int, commentLinesOfCode: int, nonCommentLinesOfCode: int}
54
     */
55
    private $linesOfCode;
56
 
57
    /**
58
     * @var int
59
     */
60
    private $numFiles = -1;
61
 
62
    /**
63
     * @var int
64
     */
65
    private $numExecutableLines = -1;
66
 
67
    /**
68
     * @var int
69
     */
70
    private $numExecutedLines = -1;
71
 
72
    /**
73
     * @var int
74
     */
75
    private $numExecutableBranches = -1;
76
 
77
    /**
78
     * @var int
79
     */
80
    private $numExecutedBranches = -1;
81
 
82
    /**
83
     * @var int
84
     */
85
    private $numExecutablePaths = -1;
86
 
87
    /**
88
     * @var int
89
     */
90
    private $numExecutedPaths = -1;
91
 
92
    /**
93
     * @var int
94
     */
95
    private $numClasses = -1;
96
 
97
    /**
98
     * @var int
99
     */
100
    private $numTestedClasses = -1;
101
 
102
    /**
103
     * @var int
104
     */
105
    private $numTraits = -1;
106
 
107
    /**
108
     * @var int
109
     */
110
    private $numTestedTraits = -1;
111
 
112
    /**
113
     * @var int
114
     */
115
    private $numMethods = -1;
116
 
117
    /**
118
     * @var int
119
     */
120
    private $numTestedMethods = -1;
121
 
122
    /**
123
     * @var int
124
     */
125
    private $numFunctions = -1;
126
 
127
    /**
128
     * @var int
129
     */
130
    private $numTestedFunctions = -1;
131
 
132
    public function count(): int
133
    {
134
        if ($this->numFiles === -1) {
135
            $this->numFiles = 0;
136
 
137
            foreach ($this->children as $child) {
138
                $this->numFiles += count($child);
139
            }
140
        }
141
 
142
        return $this->numFiles;
143
    }
144
 
145
    public function getIterator(): RecursiveIteratorIterator
146
    {
147
        return new RecursiveIteratorIterator(
148
            new Iterator($this),
149
            RecursiveIteratorIterator::SELF_FIRST
150
        );
151
    }
152
 
153
    public function addDirectory(string $name): self
154
    {
155
        $directory = new self($name, $this);
156
 
157
        $this->children[]    = $directory;
158
        $this->directories[] = &$this->children[count($this->children) - 1];
159
 
160
        return $directory;
161
    }
162
 
163
    public function addFile(File $file): void
164
    {
165
        $this->children[] = $file;
166
        $this->files[]    = &$this->children[count($this->children) - 1];
167
 
168
        $this->numExecutableLines = -1;
169
        $this->numExecutedLines   = -1;
170
    }
171
 
172
    public function directories(): array
173
    {
174
        return $this->directories;
175
    }
176
 
177
    public function files(): array
178
    {
179
        return $this->files;
180
    }
181
 
182
    public function children(): array
183
    {
184
        return $this->children;
185
    }
186
 
187
    public function classes(): array
188
    {
189
        if ($this->classes === null) {
190
            $this->classes = [];
191
 
192
            foreach ($this->children as $child) {
193
                $this->classes = array_merge(
194
                    $this->classes,
195
                    $child->classes()
196
                );
197
            }
198
        }
199
 
200
        return $this->classes;
201
    }
202
 
203
    public function traits(): array
204
    {
205
        if ($this->traits === null) {
206
            $this->traits = [];
207
 
208
            foreach ($this->children as $child) {
209
                $this->traits = array_merge(
210
                    $this->traits,
211
                    $child->traits()
212
                );
213
            }
214
        }
215
 
216
        return $this->traits;
217
    }
218
 
219
    public function functions(): array
220
    {
221
        if ($this->functions === null) {
222
            $this->functions = [];
223
 
224
            foreach ($this->children as $child) {
225
                $this->functions = array_merge(
226
                    $this->functions,
227
                    $child->functions()
228
                );
229
            }
230
        }
231
 
232
        return $this->functions;
233
    }
234
 
235
    /**
236
     * @psalm-return array{linesOfCode: int, commentLinesOfCode: int, nonCommentLinesOfCode: int}
237
     */
238
    public function linesOfCode(): array
239
    {
240
        if ($this->linesOfCode === null) {
241
            $this->linesOfCode = [
242
                'linesOfCode'           => 0,
243
                'commentLinesOfCode'    => 0,
244
                'nonCommentLinesOfCode' => 0,
245
            ];
246
 
247
            foreach ($this->children as $child) {
248
                $childLinesOfCode = $child->linesOfCode();
249
 
250
                $this->linesOfCode['linesOfCode'] += $childLinesOfCode['linesOfCode'];
251
                $this->linesOfCode['commentLinesOfCode'] += $childLinesOfCode['commentLinesOfCode'];
252
                $this->linesOfCode['nonCommentLinesOfCode'] += $childLinesOfCode['nonCommentLinesOfCode'];
253
            }
254
        }
255
 
256
        return $this->linesOfCode;
257
    }
258
 
259
    public function numberOfExecutableLines(): int
260
    {
261
        if ($this->numExecutableLines === -1) {
262
            $this->numExecutableLines = 0;
263
 
264
            foreach ($this->children as $child) {
265
                $this->numExecutableLines += $child->numberOfExecutableLines();
266
            }
267
        }
268
 
269
        return $this->numExecutableLines;
270
    }
271
 
272
    public function numberOfExecutedLines(): int
273
    {
274
        if ($this->numExecutedLines === -1) {
275
            $this->numExecutedLines = 0;
276
 
277
            foreach ($this->children as $child) {
278
                $this->numExecutedLines += $child->numberOfExecutedLines();
279
            }
280
        }
281
 
282
        return $this->numExecutedLines;
283
    }
284
 
285
    public function numberOfExecutableBranches(): int
286
    {
287
        if ($this->numExecutableBranches === -1) {
288
            $this->numExecutableBranches = 0;
289
 
290
            foreach ($this->children as $child) {
291
                $this->numExecutableBranches += $child->numberOfExecutableBranches();
292
            }
293
        }
294
 
295
        return $this->numExecutableBranches;
296
    }
297
 
298
    public function numberOfExecutedBranches(): int
299
    {
300
        if ($this->numExecutedBranches === -1) {
301
            $this->numExecutedBranches = 0;
302
 
303
            foreach ($this->children as $child) {
304
                $this->numExecutedBranches += $child->numberOfExecutedBranches();
305
            }
306
        }
307
 
308
        return $this->numExecutedBranches;
309
    }
310
 
311
    public function numberOfExecutablePaths(): int
312
    {
313
        if ($this->numExecutablePaths === -1) {
314
            $this->numExecutablePaths = 0;
315
 
316
            foreach ($this->children as $child) {
317
                $this->numExecutablePaths += $child->numberOfExecutablePaths();
318
            }
319
        }
320
 
321
        return $this->numExecutablePaths;
322
    }
323
 
324
    public function numberOfExecutedPaths(): int
325
    {
326
        if ($this->numExecutedPaths === -1) {
327
            $this->numExecutedPaths = 0;
328
 
329
            foreach ($this->children as $child) {
330
                $this->numExecutedPaths += $child->numberOfExecutedPaths();
331
            }
332
        }
333
 
334
        return $this->numExecutedPaths;
335
    }
336
 
337
    public function numberOfClasses(): int
338
    {
339
        if ($this->numClasses === -1) {
340
            $this->numClasses = 0;
341
 
342
            foreach ($this->children as $child) {
343
                $this->numClasses += $child->numberOfClasses();
344
            }
345
        }
346
 
347
        return $this->numClasses;
348
    }
349
 
350
    public function numberOfTestedClasses(): int
351
    {
352
        if ($this->numTestedClasses === -1) {
353
            $this->numTestedClasses = 0;
354
 
355
            foreach ($this->children as $child) {
356
                $this->numTestedClasses += $child->numberOfTestedClasses();
357
            }
358
        }
359
 
360
        return $this->numTestedClasses;
361
    }
362
 
363
    public function numberOfTraits(): int
364
    {
365
        if ($this->numTraits === -1) {
366
            $this->numTraits = 0;
367
 
368
            foreach ($this->children as $child) {
369
                $this->numTraits += $child->numberOfTraits();
370
            }
371
        }
372
 
373
        return $this->numTraits;
374
    }
375
 
376
    public function numberOfTestedTraits(): int
377
    {
378
        if ($this->numTestedTraits === -1) {
379
            $this->numTestedTraits = 0;
380
 
381
            foreach ($this->children as $child) {
382
                $this->numTestedTraits += $child->numberOfTestedTraits();
383
            }
384
        }
385
 
386
        return $this->numTestedTraits;
387
    }
388
 
389
    public function numberOfMethods(): int
390
    {
391
        if ($this->numMethods === -1) {
392
            $this->numMethods = 0;
393
 
394
            foreach ($this->children as $child) {
395
                $this->numMethods += $child->numberOfMethods();
396
            }
397
        }
398
 
399
        return $this->numMethods;
400
    }
401
 
402
    public function numberOfTestedMethods(): int
403
    {
404
        if ($this->numTestedMethods === -1) {
405
            $this->numTestedMethods = 0;
406
 
407
            foreach ($this->children as $child) {
408
                $this->numTestedMethods += $child->numberOfTestedMethods();
409
            }
410
        }
411
 
412
        return $this->numTestedMethods;
413
    }
414
 
415
    public function numberOfFunctions(): int
416
    {
417
        if ($this->numFunctions === -1) {
418
            $this->numFunctions = 0;
419
 
420
            foreach ($this->children as $child) {
421
                $this->numFunctions += $child->numberOfFunctions();
422
            }
423
        }
424
 
425
        return $this->numFunctions;
426
    }
427
 
428
    public function numberOfTestedFunctions(): int
429
    {
430
        if ($this->numTestedFunctions === -1) {
431
            $this->numTestedFunctions = 0;
432
 
433
            foreach ($this->children as $child) {
434
                $this->numTestedFunctions += $child->numberOfTestedFunctions();
435
            }
436
        }
437
 
438
        return $this->numTestedFunctions;
439
    }
440
}