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