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 sebastian/global-state.
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\GlobalState;
11
 
12
use function in_array;
13
use function strpos;
14
use ReflectionClass;
15
 
16
final class ExcludeList
17
{
18
    /**
19
     * @var array
20
     */
21
    private $globalVariables = [];
22
 
23
    /**
24
     * @var string[]
25
     */
26
    private $classes = [];
27
 
28
    /**
29
     * @var string[]
30
     */
31
    private $classNamePrefixes = [];
32
 
33
    /**
34
     * @var string[]
35
     */
36
    private $parentClasses = [];
37
 
38
    /**
39
     * @var string[]
40
     */
41
    private $interfaces = [];
42
 
43
    /**
44
     * @var array
45
     */
46
    private $staticAttributes = [];
47
 
48
    public function addGlobalVariable(string $variableName): void
49
    {
50
        $this->globalVariables[$variableName] = true;
51
    }
52
 
53
    public function addClass(string $className): void
54
    {
55
        $this->classes[] = $className;
56
    }
57
 
58
    public function addSubclassesOf(string $className): void
59
    {
60
        $this->parentClasses[] = $className;
61
    }
62
 
63
    public function addImplementorsOf(string $interfaceName): void
64
    {
65
        $this->interfaces[] = $interfaceName;
66
    }
67
 
68
    public function addClassNamePrefix(string $classNamePrefix): void
69
    {
70
        $this->classNamePrefixes[] = $classNamePrefix;
71
    }
72
 
73
    public function addStaticAttribute(string $className, string $attributeName): void
74
    {
75
        if (!isset($this->staticAttributes[$className])) {
76
            $this->staticAttributes[$className] = [];
77
        }
78
 
79
        $this->staticAttributes[$className][$attributeName] = true;
80
    }
81
 
82
    public function isGlobalVariableExcluded(string $variableName): bool
83
    {
84
        return isset($this->globalVariables[$variableName]);
85
    }
86
 
87
    public function isStaticAttributeExcluded(string $className, string $attributeName): bool
88
    {
89
        if (in_array($className, $this->classes, true)) {
90
            return true;
91
        }
92
 
93
        foreach ($this->classNamePrefixes as $prefix) {
94
            if (strpos($className, $prefix) === 0) {
95
                return true;
96
            }
97
        }
98
 
99
        $class = new ReflectionClass($className);
100
 
101
        foreach ($this->parentClasses as $type) {
102
            if ($class->isSubclassOf($type)) {
103
                return true;
104
            }
105
        }
106
 
107
        foreach ($this->interfaces as $type) {
108
            if ($class->implementsInterface($type)) {
109
                return true;
110
            }
111
        }
112
 
113
        if (isset($this->staticAttributes[$className][$attributeName])) {
114
            return true;
115
        }
116
 
117
        return false;
118
    }
119
}