1: | <?php |
2: | |
3: | declare(strict_types=1); |
4: | |
5: | namespace PHPStan\BetterReflection\Reflection\Adapter; |
6: | |
7: | use ReflectionUnionType as CoreReflectionUnionType; |
8: | use PHPStan\BetterReflection\Reflection\ReflectionType as BetterReflectionType; |
9: | use PHPStan\BetterReflection\Reflection\ReflectionUnionType as BetterReflectionUnionType; |
10: | |
11: | use function array_map; |
12: | use function assert; |
13: | |
14: | final class ReflectionUnionType extends CoreReflectionUnionType |
15: | { |
16: | |
17: | |
18: | |
19: | private $betterReflectionType; |
20: | public function __construct(BetterReflectionUnionType $betterReflectionType) |
21: | { |
22: | $this->betterReflectionType = $betterReflectionType; |
23: | } |
24: | |
25: | |
26: | public function getTypes(): array |
27: | { |
28: | return array_map(static function (BetterReflectionType $type) { |
29: | $adapterType = ReflectionType::fromType($type); |
30: | assert($adapterType instanceof ReflectionNamedType || $adapterType instanceof ReflectionIntersectionType); |
31: | |
32: | return $adapterType; |
33: | }, $this->betterReflectionType->getTypes()); |
34: | } |
35: | |
36: | public function __toString(): string |
37: | { |
38: | return $this->betterReflectionType->__toString(); |
39: | } |
40: | |
41: | public function allowsNull(): bool |
42: | { |
43: | return $this->betterReflectionType->allowsNull(); |
44: | } |
45: | } |
46: | |