Total Complexity | 13 |
Total Lines | 58 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8 | final class Argument |
||
9 | { |
||
10 | /** @var \ReflectionNamedType[] */ |
||
11 | private $types = []; |
||
12 | |||
13 | public function __construct(\ReflectionParameter $parameter) |
||
14 | { |
||
15 | if (!$type = $parameter->getType()) { |
||
16 | return; |
||
17 | } |
||
18 | |||
19 | if ($type instanceof \ReflectionNamedType) { |
||
20 | $this->types = [$type]; |
||
21 | |||
22 | return; |
||
23 | } |
||
24 | |||
25 | /** @var \ReflectionUnionType $type */ |
||
26 | $this->types = $type->getTypes(); |
||
27 | } |
||
28 | |||
29 | public function type(): ?string |
||
30 | { |
||
31 | return $this->hasType() ? \implode('|', $this->types()) : null; |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * @return string[] |
||
36 | */ |
||
37 | public function types(): array |
||
38 | { |
||
39 | return \array_map(static function(\ReflectionNamedType $type) { return $type->getName(); }, $this->types); |
||
40 | } |
||
41 | |||
42 | public function hasType(): bool |
||
43 | { |
||
44 | return !empty($this->types); |
||
45 | } |
||
46 | |||
47 | public function isUnionType(): bool |
||
50 | } |
||
51 | |||
52 | public function supports(string $type): bool |
||
66 | } |
||
67 | } |
||
68 |