Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | 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
150 lars 66
        ClassLoader::class        => 1,
148 lars 67
 
68
        // doctrine/instantiator
150 lars 69
        Instantiator::class       => 1,
148 lars 70
 
71
        // myclabs/deepcopy
150 lars 72
        DeepCopy::class           => 1,
148 lars 73
 
74
        // nikic/php-parser
150 lars 75
        Parser::class             => 1,
148 lars 76
 
77
        // phar-io/manifest
150 lars 78
        Manifest::class           => 1,
148 lars 79
 
80
        // phar-io/version
150 lars 81
        PharIoVersion::class      => 1,
148 lars 82
 
83
        // phpdocumentor/reflection-common
150 lars 84
        Project::class            => 1,
148 lars 85
 
86
        // phpdocumentor/reflection-docblock
150 lars 87
        DocBlock::class           => 1,
148 lars 88
 
89
        // phpdocumentor/type-resolver
150 lars 90
        Type::class               => 1,
148 lars 91
 
92
        // phpspec/prophecy
150 lars 93
        Prophet::class            => 1,
148 lars 94
 
95
        // phpunit/phpunit
150 lars 96
        TestCase::class           => 2,
148 lars 97
 
98
        // phpunit/php-code-coverage
150 lars 99
        CodeCoverage::class       => 1,
148 lars 100
 
101
        // phpunit/php-file-iterator
102
        FileIteratorFacade::class => 1,
103
 
104
        // phpunit/php-invoker
150 lars 105
        Invoker::class            => 1,
148 lars 106
 
107
        // phpunit/php-text-template
150 lars 108
        Template::class           => 1,
148 lars 109
 
110
        // phpunit/php-timer
150 lars 111
        Timer::class              => 1,
148 lars 112
 
113
        // sebastian/cli-parser
150 lars 114
        CliParser::class          => 1,
148 lars 115
 
116
        // sebastian/code-unit
150 lars 117
        CodeUnit::class           => 1,
148 lars 118
 
119
        // sebastian/code-unit-reverse-lookup
150 lars 120
        Wizard::class             => 1,
148 lars 121
 
122
        // sebastian/comparator
150 lars 123
        Comparator::class         => 1,
148 lars 124
 
125
        // sebastian/complexity
150 lars 126
        Calculator::class         => 1,
148 lars 127
 
128
        // sebastian/diff
150 lars 129
        Diff::class               => 1,
148 lars 130
 
131
        // sebastian/environment
150 lars 132
        Runtime::class            => 1,
148 lars 133
 
134
        // sebastian/exporter
150 lars 135
        Exporter::class           => 1,
148 lars 136
 
137
        // sebastian/global-state
150 lars 138
        Snapshot::class           => 1,
148 lars 139
 
140
        // sebastian/lines-of-code
150 lars 141
        Counter::class            => 1,
148 lars 142
 
143
        // sebastian/object-enumerator
150 lars 144
        Enumerator::class         => 1,
148 lars 145
 
146
        // sebastian/recursion-context
150 lars 147
        Context::class            => 1,
148 lars 148
 
149
        // sebastian/resource-operations
150
        ResourceOperations::class => 1,
151
 
152
        // sebastian/type
150 lars 153
        TypeName::class           => 1,
148 lars 154
 
155
        // sebastian/version
150 lars 156
        Version::class            => 1,
148 lars 157
 
158
        // theseer/tokenizer
150 lars 159
        Tokenizer::class          => 1,
148 lars 160
 
161
        // webmozart/assert
150 lars 162
        Assert::class             => 1,
148 lars 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
}