1: | <?php |
2: | |
3: | declare(strict_types=1); |
4: | |
5: | namespace PHPStan\BetterReflection\Reflection; |
6: | |
7: | use PhpParser\Node; |
8: | use PhpParser\Node\IntersectionType; |
9: | use PHPStan\BetterReflection\Reflector\Reflector; |
10: | |
11: | use function array_map; |
12: | use function assert; |
13: | use function implode; |
14: | |
15: | |
16: | class ReflectionIntersectionType extends ReflectionType |
17: | { |
18: | |
19: | private $types; |
20: | |
21: | |
22: | |
23: | public function __construct(Reflector $reflector, $owner, IntersectionType $type) |
24: | { |
25: | |
26: | $types = array_map(static function ($type) use ($reflector, $owner): ReflectionNamedType { |
27: | $type = ReflectionType::createFromNode($reflector, $owner, $type); |
28: | assert($type instanceof ReflectionNamedType); |
29: | |
30: | return $type; |
31: | }, $type->types); |
32: | $this->types = $types; |
33: | } |
34: | |
35: | |
36: | |
37: | |
38: | public function withOwner($owner) |
39: | { |
40: | $clone = clone $this; |
41: | |
42: | foreach ($clone->types as $typeNo => $innerType) { |
43: | $clone->types[$typeNo] = $innerType->withOwner($owner); |
44: | } |
45: | |
46: | return $clone; |
47: | } |
48: | |
49: | |
50: | public function getTypes(): array |
51: | { |
52: | return $this->types; |
53: | } |
54: | |
55: | |
56: | public function allowsNull(): bool |
57: | { |
58: | return false; |
59: | } |
60: | |
61: | |
62: | public function __toString(): string |
63: | { |
64: | |
65: | return implode('&', array_map(static function (ReflectionNamedType $type) : string { |
66: | return $type->__toString(); |
67: | }, $this->types)); |
68: | } |
69: | } |
70: | |