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.
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 PHPUnit\TextUI\XmlConfiguration\CodeCoverage;
11
 
12
use function count;
13
use PHPUnit\TextUI\XmlConfiguration\CodeCoverage\Filter\DirectoryCollection;
14
use PHPUnit\TextUI\XmlConfiguration\CodeCoverage\Report\Clover;
15
use PHPUnit\TextUI\XmlConfiguration\CodeCoverage\Report\Cobertura;
16
use PHPUnit\TextUI\XmlConfiguration\CodeCoverage\Report\Crap4j;
17
use PHPUnit\TextUI\XmlConfiguration\CodeCoverage\Report\Html;
18
use PHPUnit\TextUI\XmlConfiguration\CodeCoverage\Report\Php;
19
use PHPUnit\TextUI\XmlConfiguration\CodeCoverage\Report\Text;
20
use PHPUnit\TextUI\XmlConfiguration\CodeCoverage\Report\Xml;
21
use PHPUnit\TextUI\XmlConfiguration\Directory;
22
use PHPUnit\TextUI\XmlConfiguration\Exception;
23
use PHPUnit\TextUI\XmlConfiguration\FileCollection;
24
 
25
/**
26
 * @internal This class is not covered by the backward compatibility promise for PHPUnit
27
 *
28
 * @psalm-immutable
29
 */
30
final class CodeCoverage
31
{
32
    /**
33
     * @var ?Directory
34
     */
35
    private $cacheDirectory;
36
 
37
    /**
38
     * @var DirectoryCollection
39
     */
40
    private $directories;
41
 
42
    /**
43
     * @var FileCollection
44
     */
45
    private $files;
46
 
47
    /**
48
     * @var DirectoryCollection
49
     */
50
    private $excludeDirectories;
51
 
52
    /**
53
     * @var FileCollection
54
     */
55
    private $excludeFiles;
56
 
57
    /**
58
     * @var bool
59
     */
60
    private $pathCoverage;
61
 
62
    /**
63
     * @var bool
64
     */
65
    private $includeUncoveredFiles;
66
 
67
    /**
68
     * @var bool
69
     */
70
    private $processUncoveredFiles;
71
 
72
    /**
73
     * @var bool
74
     */
75
    private $ignoreDeprecatedCodeUnits;
76
 
77
    /**
78
     * @var bool
79
     */
80
    private $disableCodeCoverageIgnore;
81
 
82
    /**
83
     * @var ?Clover
84
     */
85
    private $clover;
86
 
87
    /**
88
     * @var ?Cobertura
89
     */
90
    private $cobertura;
91
 
92
    /**
93
     * @var ?Crap4j
94
     */
95
    private $crap4j;
96
 
97
    /**
98
     * @var ?Html
99
     */
100
    private $html;
101
 
102
    /**
103
     * @var ?Php
104
     */
105
    private $php;
106
 
107
    /**
108
     * @var ?Text
109
     */
110
    private $text;
111
 
112
    /**
113
     * @var ?Xml
114
     */
115
    private $xml;
116
 
117
    public function __construct(?Directory $cacheDirectory, DirectoryCollection $directories, FileCollection $files, DirectoryCollection $excludeDirectories, FileCollection $excludeFiles, bool $pathCoverage, bool $includeUncoveredFiles, bool $processUncoveredFiles, bool $ignoreDeprecatedCodeUnits, bool $disableCodeCoverageIgnore, ?Clover $clover, ?Cobertura $cobertura, ?Crap4j $crap4j, ?Html $html, ?Php $php, ?Text $text, ?Xml $xml)
118
    {
119
        $this->cacheDirectory            = $cacheDirectory;
120
        $this->directories               = $directories;
121
        $this->files                     = $files;
122
        $this->excludeDirectories        = $excludeDirectories;
123
        $this->excludeFiles              = $excludeFiles;
124
        $this->pathCoverage              = $pathCoverage;
125
        $this->includeUncoveredFiles     = $includeUncoveredFiles;
126
        $this->processUncoveredFiles     = $processUncoveredFiles;
127
        $this->ignoreDeprecatedCodeUnits = $ignoreDeprecatedCodeUnits;
128
        $this->disableCodeCoverageIgnore = $disableCodeCoverageIgnore;
129
        $this->clover                    = $clover;
130
        $this->cobertura                 = $cobertura;
131
        $this->crap4j                    = $crap4j;
132
        $this->html                      = $html;
133
        $this->php                       = $php;
134
        $this->text                      = $text;
135
        $this->xml                       = $xml;
136
    }
137
 
138
    /**
139
     * @psalm-assert-if-true !null $this->cacheDirectory
140
     */
141
    public function hasCacheDirectory(): bool
142
    {
143
        return $this->cacheDirectory !== null;
144
    }
145
 
146
    /**
147
     * @throws Exception
148
     */
149
    public function cacheDirectory(): Directory
150
    {
151
        if (!$this->hasCacheDirectory()) {
152
            throw new Exception(
153
                'No cache directory has been configured'
154
            );
155
        }
156
 
157
        return $this->cacheDirectory;
158
    }
159
 
160
    public function hasNonEmptyListOfFilesToBeIncludedInCodeCoverageReport(): bool
161
    {
162
        return count($this->directories) > 0 || count($this->files) > 0;
163
    }
164
 
165
    public function directories(): DirectoryCollection
166
    {
167
        return $this->directories;
168
    }
169
 
170
    public function files(): FileCollection
171
    {
172
        return $this->files;
173
    }
174
 
175
    public function excludeDirectories(): DirectoryCollection
176
    {
177
        return $this->excludeDirectories;
178
    }
179
 
180
    public function excludeFiles(): FileCollection
181
    {
182
        return $this->excludeFiles;
183
    }
184
 
185
    public function pathCoverage(): bool
186
    {
187
        return $this->pathCoverage;
188
    }
189
 
190
    public function includeUncoveredFiles(): bool
191
    {
192
        return $this->includeUncoveredFiles;
193
    }
194
 
195
    public function ignoreDeprecatedCodeUnits(): bool
196
    {
197
        return $this->ignoreDeprecatedCodeUnits;
198
    }
199
 
200
    public function disableCodeCoverageIgnore(): bool
201
    {
202
        return $this->disableCodeCoverageIgnore;
203
    }
204
 
205
    public function processUncoveredFiles(): bool
206
    {
207
        return $this->processUncoveredFiles;
208
    }
209
 
210
    /**
211
     * @psalm-assert-if-true !null $this->clover
212
     */
213
    public function hasClover(): bool
214
    {
215
        return $this->clover !== null;
216
    }
217
 
218
    /**
219
     * @throws Exception
220
     */
221
    public function clover(): Clover
222
    {
223
        if (!$this->hasClover()) {
224
            throw new Exception(
225
                'Code Coverage report "Clover XML" has not been configured'
226
            );
227
        }
228
 
229
        return $this->clover;
230
    }
231
 
232
    /**
233
     * @psalm-assert-if-true !null $this->cobertura
234
     */
235
    public function hasCobertura(): bool
236
    {
237
        return $this->cobertura !== null;
238
    }
239
 
240
    /**
241
     * @throws Exception
242
     */
243
    public function cobertura(): Cobertura
244
    {
245
        if (!$this->hasCobertura()) {
246
            throw new Exception(
247
                'Code Coverage report "Cobertura XML" has not been configured'
248
            );
249
        }
250
 
251
        return $this->cobertura;
252
    }
253
 
254
    /**
255
     * @psalm-assert-if-true !null $this->crap4j
256
     */
257
    public function hasCrap4j(): bool
258
    {
259
        return $this->crap4j !== null;
260
    }
261
 
262
    /**
263
     * @throws Exception
264
     */
265
    public function crap4j(): Crap4j
266
    {
267
        if (!$this->hasCrap4j()) {
268
            throw new Exception(
269
                'Code Coverage report "Crap4J" has not been configured'
270
            );
271
        }
272
 
273
        return $this->crap4j;
274
    }
275
 
276
    /**
277
     * @psalm-assert-if-true !null $this->html
278
     */
279
    public function hasHtml(): bool
280
    {
281
        return $this->html !== null;
282
    }
283
 
284
    /**
285
     * @throws Exception
286
     */
287
    public function html(): Html
288
    {
289
        if (!$this->hasHtml()) {
290
            throw new Exception(
291
                'Code Coverage report "HTML" has not been configured'
292
            );
293
        }
294
 
295
        return $this->html;
296
    }
297
 
298
    /**
299
     * @psalm-assert-if-true !null $this->php
300
     */
301
    public function hasPhp(): bool
302
    {
303
        return $this->php !== null;
304
    }
305
 
306
    /**
307
     * @throws Exception
308
     */
309
    public function php(): Php
310
    {
311
        if (!$this->hasPhp()) {
312
            throw new Exception(
313
                'Code Coverage report "PHP" has not been configured'
314
            );
315
        }
316
 
317
        return $this->php;
318
    }
319
 
320
    /**
321
     * @psalm-assert-if-true !null $this->text
322
     */
323
    public function hasText(): bool
324
    {
325
        return $this->text !== null;
326
    }
327
 
328
    /**
329
     * @throws Exception
330
     */
331
    public function text(): Text
332
    {
333
        if (!$this->hasText()) {
334
            throw new Exception(
335
                'Code Coverage report "Text" has not been configured'
336
            );
337
        }
338
 
339
        return $this->text;
340
    }
341
 
342
    /**
343
     * @psalm-assert-if-true !null $this->xml
344
     */
345
    public function hasXml(): bool
346
    {
347
        return $this->xml !== null;
348
    }
349
 
350
    /**
351
     * @throws Exception
352
     */
353
    public function xml(): Xml
354
    {
355
        if (!$this->hasXml()) {
356
            throw new Exception(
357
                'Code Coverage report "XML" has not been configured'
358
            );
359
        }
360
 
361
        return $this->xml;
362
    }
363
}