| 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: | |
| 15: | final class ReflectionUnionType extends CoreReflectionUnionType |
| 16: | { |
| 17: | private BetterReflectionUnionType $betterReflectionType; |
| 18: | public function __construct(BetterReflectionUnionType $betterReflectionType) |
| 19: | { |
| 20: | $this->betterReflectionType = $betterReflectionType; |
| 21: | } |
| 22: | |
| 23: | |
| 24: | public function getTypes(): array |
| 25: | { |
| 26: | return array_map(static function (BetterReflectionType $type) { |
| 27: | $adapterType = ReflectionType::fromType($type); |
| 28: | assert($adapterType instanceof ReflectionNamedType || $adapterType instanceof ReflectionIntersectionType); |
| 29: | |
| 30: | return $adapterType; |
| 31: | }, $this->betterReflectionType->getTypes()); |
| 32: | } |
| 33: | |
| 34: | |
| 35: | public function __toString(): string |
| 36: | { |
| 37: | return $this->betterReflectionType->__toString(); |
| 38: | } |
| 39: | |
| 40: | public function allowsNull(): bool |
| 41: | { |
| 42: | return $this->betterReflectionType->allowsNull(); |
| 43: | } |
| 44: | } |
| 45: | |