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 const DIRECTORY_SEPARATOR;
13
use function array_merge;
14
use function str_replace;
15
use function substr;
16
use Countable;
17
use SebastianBergmann\CodeCoverage\Util\Percentage;
18
 
19
/**
20
 * @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
21
 */
22
abstract class AbstractNode implements Countable
23
{
24
    /**
25
     * @var string
26
     */
27
    private $name;
28
 
29
    /**
30
     * @var string
31
     */
32
    private $pathAsString;
33
 
34
    /**
35
     * @var array
36
     */
37
    private $pathAsArray;
38
 
39
    /**
40
     * @var AbstractNode
41
     */
42
    private $parent;
43
 
44
    /**
45
     * @var string
46
     */
47
    private $id;
48
 
49
    public function __construct(string $name, self $parent = null)
50
    {
51
        if (substr($name, -1) === DIRECTORY_SEPARATOR) {
52
            $name = substr($name, 0, -1);
53
        }
54
 
55
        $this->name   = $name;
56
        $this->parent = $parent;
57
    }
58
 
59
    public function name(): string
60
    {
61
        return $this->name;
62
    }
63
 
64
    public function id(): string
65
    {
66
        if ($this->id === null) {
67
            $parent = $this->parent();
68
 
69
            if ($parent === null) {
70
                $this->id = 'index';
71
            } else {
72
                $parentId = $parent->id();
73
 
74
                if ($parentId === 'index') {
75
                    $this->id = str_replace(':', '_', $this->name);
76
                } else {
77
                    $this->id = $parentId . '/' . $this->name;
78
                }
79
            }
80
        }
81
 
82
        return $this->id;
83
    }
84
 
85
    public function pathAsString(): string
86
    {
87
        if ($this->pathAsString === null) {
88
            if ($this->parent === null) {
89
                $this->pathAsString = $this->name;
90
            } else {
91
                $this->pathAsString = $this->parent->pathAsString() . DIRECTORY_SEPARATOR . $this->name;
92
            }
93
        }
94
 
95
        return $this->pathAsString;
96
    }
97
 
98
    public function pathAsArray(): array
99
    {
100
        if ($this->pathAsArray === null) {
101
            if ($this->parent === null) {
102
                $this->pathAsArray = [];
103
            } else {
104
                $this->pathAsArray = $this->parent->pathAsArray();
105
            }
106
 
107
            $this->pathAsArray[] = $this;
108
        }
109
 
110
        return $this->pathAsArray;
111
    }
112
 
113
    public function parent(): ?self
114
    {
115
        return $this->parent;
116
    }
117
 
118
    public function percentageOfTestedClasses(): Percentage
119
    {
120
        return Percentage::fromFractionAndTotal(
121
            $this->numberOfTestedClasses(),
122
            $this->numberOfClasses(),
123
        );
124
    }
125
 
126
    public function percentageOfTestedTraits(): Percentage
127
    {
128
        return Percentage::fromFractionAndTotal(
129
            $this->numberOfTestedTraits(),
130
            $this->numberOfTraits(),
131
        );
132
    }
133
 
134
    public function percentageOfTestedClassesAndTraits(): Percentage
135
    {
136
        return Percentage::fromFractionAndTotal(
137
            $this->numberOfTestedClassesAndTraits(),
138
            $this->numberOfClassesAndTraits(),
139
        );
140
    }
141
 
142
    public function percentageOfTestedFunctions(): Percentage
143
    {
144
        return Percentage::fromFractionAndTotal(
145
            $this->numberOfTestedFunctions(),
146
            $this->numberOfFunctions(),
147
        );
148
    }
149
 
150
    public function percentageOfTestedMethods(): Percentage
151
    {
152
        return Percentage::fromFractionAndTotal(
153
            $this->numberOfTestedMethods(),
154
            $this->numberOfMethods(),
155
        );
156
    }
157
 
158
    public function percentageOfTestedFunctionsAndMethods(): Percentage
159
    {
160
        return Percentage::fromFractionAndTotal(
161
            $this->numberOfTestedFunctionsAndMethods(),
162
            $this->numberOfFunctionsAndMethods(),
163
        );
164
    }
165
 
166
    public function percentageOfExecutedLines(): Percentage
167
    {
168
        return Percentage::fromFractionAndTotal(
169
            $this->numberOfExecutedLines(),
170
            $this->numberOfExecutableLines(),
171
        );
172
    }
173
 
174
    public function percentageOfExecutedBranches(): Percentage
175
    {
176
        return Percentage::fromFractionAndTotal(
177
            $this->numberOfExecutedBranches(),
178
            $this->numberOfExecutableBranches()
179
        );
180
    }
181
 
182
    public function percentageOfExecutedPaths(): Percentage
183
    {
184
        return Percentage::fromFractionAndTotal(
185
            $this->numberOfExecutedPaths(),
186
            $this->numberOfExecutablePaths()
187
        );
188
    }
189
 
190
    public function numberOfClassesAndTraits(): int
191
    {
192
        return $this->numberOfClasses() + $this->numberOfTraits();
193
    }
194
 
195
    public function numberOfTestedClassesAndTraits(): int
196
    {
197
        return $this->numberOfTestedClasses() + $this->numberOfTestedTraits();
198
    }
199
 
200
    public function classesAndTraits(): array
201
    {
202
        return array_merge($this->classes(), $this->traits());
203
    }
204
 
205
    public function numberOfFunctionsAndMethods(): int
206
    {
207
        return $this->numberOfFunctions() + $this->numberOfMethods();
208
    }
209
 
210
    public function numberOfTestedFunctionsAndMethods(): int
211
    {
212
        return $this->numberOfTestedFunctions() + $this->numberOfTestedMethods();
213
    }
214
 
215
    abstract public function classes(): array;
216
 
217
    abstract public function traits(): array;
218
 
219
    abstract public function functions(): array;
220
 
221
    /**
222
     * @psalm-return array{linesOfCode: int, commentLinesOfCode: int, nonCommentLinesOfCode: int}
223
     */
224
    abstract public function linesOfCode(): array;
225
 
226
    abstract public function numberOfExecutableLines(): int;
227
 
228
    abstract public function numberOfExecutedLines(): int;
229
 
230
    abstract public function numberOfExecutableBranches(): int;
231
 
232
    abstract public function numberOfExecutedBranches(): int;
233
 
234
    abstract public function numberOfExecutablePaths(): int;
235
 
236
    abstract public function numberOfExecutedPaths(): int;
237
 
238
    abstract public function numberOfClasses(): int;
239
 
240
    abstract public function numberOfTestedClasses(): int;
241
 
242
    abstract public function numberOfTraits(): int;
243
 
244
    abstract public function numberOfTestedTraits(): int;
245
 
246
    abstract public function numberOfMethods(): int;
247
 
248
    abstract public function numberOfTestedMethods(): int;
249
 
250
    abstract public function numberOfFunctions(): int;
251
 
252
    abstract public function numberOfTestedFunctions(): int;
253
}