|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Part of SplTypes package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Adrien Loyant <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Ducks\Component\SplTypes\Reflection; |
|
15
|
|
|
|
|
16
|
|
|
use Ducks\Component\SplTypes\SplUnitEnum; |
|
17
|
|
|
|
|
18
|
|
|
class SplReflectionEnumUnitCase extends \ReflectionClassConstant |
|
19
|
|
|
{ |
|
20
|
|
|
private static array $instances = []; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Instantiates a SplReflectionEnumUnitCase object |
|
24
|
|
|
* |
|
25
|
|
|
* @param object|string $class An enum instance or a name. |
|
26
|
|
|
* @param string $constant An enum constant name. |
|
27
|
|
|
* |
|
28
|
|
|
* @throws ReflectionException if $class is not a SplReflectionEnumUnitCase |
|
29
|
|
|
* |
|
30
|
|
|
* @link https://www.php.net/manual/en/reflectionenumunitcase.construct.php |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct($class, string $constant) |
|
33
|
|
|
{ |
|
34
|
|
|
parent::__construct($class, $constant); |
|
35
|
|
|
|
|
36
|
|
|
if (!$this->getEnum()->hasCase($constant)) { |
|
37
|
|
|
throw new \ReflectionException( |
|
38
|
|
|
'Enum case ' . $this->class . '::' . $this->name . ' is not a case' |
|
39
|
|
|
); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Gets the reflection of the enum of this case |
|
45
|
|
|
* |
|
46
|
|
|
* @return ReflectionEnum instance describing the Enum this case belongs to. |
|
|
|
|
|
|
47
|
|
|
* |
|
48
|
|
|
* @link https://www.php.net/manual/en/reflectionenumunitcase.getenum.php |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getEnum(): SplReflectionEnum |
|
51
|
|
|
{ |
|
52
|
|
|
return new SplReflectionEnum($this->class); |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Gets the enum case object described by this reflection object |
|
57
|
|
|
* |
|
58
|
|
|
* @return SplUnitEnum The enum case object described by this reflection object. |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getValue(): SplUnitEnum |
|
61
|
|
|
{ |
|
62
|
|
|
if (!isset(self::$instances[$this->class][$this->name])) { |
|
63
|
|
|
$class = $this->getDeclaringClass(); |
|
64
|
|
|
$instance = $class->newInstanceWithoutConstructor(); |
|
65
|
|
|
|
|
66
|
|
|
$object = $class->getConstructor(); |
|
67
|
|
|
$object->setAccessible(true); |
|
68
|
|
|
$object->invoke($instance); |
|
69
|
|
|
|
|
70
|
|
|
if ($class->hasProperty('name')) { |
|
71
|
|
|
$property = $class->getProperty('name'); |
|
72
|
|
|
$property->setAccessible(true); |
|
73
|
|
|
$property->setValue($instance, $this->name); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
self::$instances[$this->class][$this->name] = $instance; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
return self::$instances[$this->class][$this->name]; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths