Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 150 | Zur aktuellen 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\Util;
11
 
12
use const DIRECTORY_SEPARATOR;
13
use function class_exists;
14
use function defined;
15
use function dirname;
16
use function is_dir;
17
use function realpath;
18
use function sprintf;
19
use function strpos;
20
use function sys_get_temp_dir;
21
use Composer\Autoload\ClassLoader;
22
use DeepCopy\DeepCopy;
23
use Doctrine\Instantiator\Instantiator;
24
use PharIo\Manifest\Manifest;
25
use PharIo\Version\Version as PharIoVersion;
26
use phpDocumentor\Reflection\DocBlock;
27
use phpDocumentor\Reflection\Project;
28
use phpDocumentor\Reflection\Type;
29
use PhpParser\Parser;
30
use PHPUnit\Framework\TestCase;
31
use Prophecy\Prophet;
32
use ReflectionClass;
33
use SebastianBergmann\CliParser\Parser as CliParser;
34
use SebastianBergmann\CodeCoverage\CodeCoverage;
35
use SebastianBergmann\CodeUnit\CodeUnit;
36
use SebastianBergmann\CodeUnitReverseLookup\Wizard;
37
use SebastianBergmann\Comparator\Comparator;
38
use SebastianBergmann\Complexity\Calculator;
39
use SebastianBergmann\Diff\Diff;
40
use SebastianBergmann\Environment\Runtime;
41
use SebastianBergmann\Exporter\Exporter;
42
use SebastianBergmann\FileIterator\Facade as FileIteratorFacade;
43
use SebastianBergmann\GlobalState\Snapshot;
44
use SebastianBergmann\Invoker\Invoker;
45
use SebastianBergmann\LinesOfCode\Counter;
46
use SebastianBergmann\ObjectEnumerator\Enumerator;
47
use SebastianBergmann\RecursionContext\Context;
48
use SebastianBergmann\ResourceOperations\ResourceOperations;
49
use SebastianBergmann\Template\Template;
50
use SebastianBergmann\Timer\Timer;
51
use SebastianBergmann\Type\TypeName;
52
use SebastianBergmann\Version;
53
use TheSeer\Tokenizer\Tokenizer;
54
use Webmozart\Assert\Assert;
55
 
56
/**
57
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
58
 */
59
final class ExcludeList
60
{
61
    /**
62
     * @var array<string,int>
63
     */
64
    private const EXCLUDED_CLASS_NAMES = [
65
        // composer
66
        ClassLoader::class => 1,
67
 
68
        // doctrine/instantiator
69
        Instantiator::class => 1,
70
 
71
        // myclabs/deepcopy
72
        DeepCopy::class => 1,
73
 
74
        // nikic/php-parser
75
        Parser::class => 1,
76
 
77
        // phar-io/manifest
78
        Manifest::class => 1,
79
 
80
        // phar-io/version
81
        PharIoVersion::class => 1,
82
 
83
        // phpdocumentor/reflection-common
84
        Project::class => 1,
85
 
86
        // phpdocumentor/reflection-docblock
87
        DocBlock::class => 1,
88
 
89
        // phpdocumentor/type-resolver
90
        Type::class => 1,
91
 
92
        // phpspec/prophecy
93
        Prophet::class => 1,
94
 
95
        // phpunit/phpunit
96
        TestCase::class => 2,
97
 
98
        // phpunit/php-code-coverage
99
        CodeCoverage::class => 1,
100
 
101
        // phpunit/php-file-iterator
102
        FileIteratorFacade::class => 1,
103
 
104
        // phpunit/php-invoker
105
        Invoker::class => 1,
106
 
107
        // phpunit/php-text-template
108
        Template::class => 1,
109
 
110
        // phpunit/php-timer
111
        Timer::class => 1,
112
 
113
        // sebastian/cli-parser
114
        CliParser::class => 1,
115
 
116
        // sebastian/code-unit
117
        CodeUnit::class => 1,
118
 
119
        // sebastian/code-unit-reverse-lookup
120
        Wizard::class => 1,
121
 
122
        // sebastian/comparator
123
        Comparator::class => 1,
124
 
125
        // sebastian/complexity
126
        Calculator::class => 1,
127
 
128
        // sebastian/diff
129
        Diff::class => 1,
130
 
131
        // sebastian/environment
132
        Runtime::class => 1,
133
 
134
        // sebastian/exporter
135
        Exporter::class => 1,
136
 
137
        // sebastian/global-state
138
        Snapshot::class => 1,
139
 
140
        // sebastian/lines-of-code
141
        Counter::class => 1,
142
 
143
        // sebastian/object-enumerator
144
        Enumerator::class => 1,
145
 
146
        // sebastian/recursion-context
147
        Context::class => 1,
148
 
149
        // sebastian/resource-operations
150
        ResourceOperations::class => 1,
151
 
152
        // sebastian/type
153
        TypeName::class => 1,
154
 
155
        // sebastian/version
156
        Version::class => 1,
157
 
158
        // theseer/tokenizer
159
        Tokenizer::class => 1,
160
 
161
        // webmozart/assert
162
        Assert::class => 1,
163
    ];
164
 
165
    /**
166
     * @var string[]
167
     */
168
    private static $directories = [];
169
 
170
    /**
171
     * @var bool
172
     */
173
    private static $initialized = false;
174
 
175
    public static function addDirectory(string $directory): void
176
    {
177
        if (!is_dir($directory)) {
178
            throw new Exception(
179
                sprintf(
180
                    '"%s" is not a directory',
181
                    $directory
182
                )
183
            );
184
        }
185
 
186
        self::$directories[] = realpath($directory);
187
    }
188
 
189
    /**
190
     * @throws Exception
191
     *
192
     * @return string[]
193
     */
194
    public function getExcludedDirectories(): array
195
    {
196
        $this->initialize();
197
 
198
        return self::$directories;
199
    }
200
 
201
    /**
202
     * @throws Exception
203
     */
204
    public function isExcluded(string $file): bool
205
    {
206
        if (defined('PHPUNIT_TESTSUITE')) {
207
            return false;
208
        }
209
 
210
        $this->initialize();
211
 
212
        foreach (self::$directories as $directory) {
213
            if (strpos($file, $directory) === 0) {
214
                return true;
215
            }
216
        }
217
 
218
        return false;
219
    }
220
 
221
    /**
222
     * @throws Exception
223
     */
224
    private function initialize(): void
225
    {
226
        if (self::$initialized) {
227
            return;
228
        }
229
 
230
        foreach (self::EXCLUDED_CLASS_NAMES as $className => $parent) {
231
            if (!class_exists($className)) {
232
                continue;
233
            }
234
 
235
            $directory = (new ReflectionClass($className))->getFileName();
236
 
237
            for ($i = 0; $i < $parent; $i++) {
238
                $directory = dirname($directory);
239
            }
240
 
241
            self::$directories[] = $directory;
242
        }
243
 
244
        // Hide process isolation workaround on Windows.
245
        if (DIRECTORY_SEPARATOR === '\\') {
246
            // tempnam() prefix is limited to first 3 chars.
247
            // @see https://php.net/manual/en/function.tempnam.php
248
            self::$directories[] = sys_get_temp_dir() . '\\PHP';
249
        }
250
 
251
        self::$initialized = true;
252
    }
253
}