Total Complexity | 7 |
Total Lines | 101 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
10 | class SplReflectionNamedType extends \ReflectionNamedType |
||
11 | { |
||
12 | private const BUILT_IN_TYPES = [ |
||
13 | 'int', |
||
14 | 'float', |
||
15 | 'string', |
||
16 | 'bool', |
||
17 | 'callable', |
||
18 | 'self', |
||
19 | 'parent', |
||
20 | 'array', |
||
21 | 'iterable', |
||
22 | 'object', |
||
23 | 'void', |
||
24 | 'mixed', |
||
25 | 'static', |
||
26 | 'null', |
||
27 | 'never', |
||
28 | 'false', |
||
29 | 'true', |
||
30 | ]; |
||
31 | |||
32 | /** |
||
33 | * The $name replacement |
||
34 | * |
||
35 | * @var string |
||
36 | * |
||
37 | * @phpstan-var non-empty-string |
||
38 | */ |
||
39 | private string $naming; |
||
40 | |||
41 | /** |
||
42 | * The $allowsNull replacement |
||
43 | * |
||
44 | * @var boolean |
||
45 | */ |
||
46 | private bool $nullable; |
||
47 | |||
48 | /** |
||
49 | * Build a fake \ReflectionNamedType |
||
50 | * |
||
51 | * @param string $name |
||
52 | * @param boolean $nullable |
||
53 | * |
||
54 | * @phpstan-param non-empty-string $name |
||
55 | * @phpstan-param boolean $nullable |
||
56 | */ |
||
57 | 11 | public function __construct(string $name, bool $nullable = false) |
|
58 | { |
||
59 | 11 | $this->naming = $name; |
|
60 | |||
61 | // Force nullable for native type name |
||
62 | 11 | switch (\strtolower($name)) { |
|
63 | 11 | case 'mixed': |
|
64 | 10 | case 'null': |
|
65 | 2 | $this->nullable = true; |
|
66 | 2 | break; |
|
67 | default: |
||
68 | 9 | $this->nullable = $nullable; |
|
69 | 9 | break; |
|
70 | } |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @inheritDoc |
||
75 | * |
||
76 | * @see https://www.php.net/manual/en/reflectionnamedtype.getname.php |
||
77 | */ |
||
78 | 11 | public function getName(): string |
|
79 | { |
||
80 | 11 | return $this->naming; |
|
81 | } |
||
82 | |||
83 | /** |
||
84 | * @inheritDoc |
||
85 | * |
||
86 | * @see https://php.net/manual/en/reflectiontype.isbuiltin.php |
||
87 | */ |
||
88 | 11 | public function isBuiltin(): bool |
|
91 | } |
||
92 | |||
93 | /** |
||
94 | * @inheritDoc |
||
95 | * |
||
96 | * @see https://www.php.net/manual/fr/reflectiontype.allowsnull.php |
||
97 | */ |
||
98 | 11 | public function allowsNull(): bool |
|
99 | { |
||
100 | 11 | return $this->nullable; |
|
101 | } |
||
102 | |||
103 | /** |
||
104 | * @inheritDoc |
||
105 | * |
||
106 | * @see https://www.php.net/manual/fr/reflectiontype.tostring.php |
||
107 | */ |
||
108 | 11 | public function __toString(): string |
|
111 | } |
||
112 | } |
||
113 |