1: <?php
2:
3: declare(strict_types=1);
4:
5: namespace PHPStan\BetterReflection\Reflection\Adapter;
6:
7: use ReflectionIntersectionType as CoreReflectionIntersectionType;
8: use PHPStan\BetterReflection\Reflection\ReflectionIntersectionType as BetterReflectionIntersectionType;
9: use PHPStan\BetterReflection\Reflection\ReflectionNamedType as BetterReflectionNamedType;
10:
11: use function array_map;
12: use function assert;
13:
14: /** @psalm-immutable */
15: class ReflectionIntersectionType extends CoreReflectionIntersectionType
16: {
17: /**
18: * @var BetterReflectionIntersectionType
19: */
20: private $betterReflectionType;
21: public function __construct(BetterReflectionIntersectionType $betterReflectionType)
22: {
23: $this->betterReflectionType = $betterReflectionType;
24: }
25:
26: /** @return non-empty-list<ReflectionNamedType> */
27: public function getTypes(): array
28: {
29: return array_map(static function (BetterReflectionNamedType $type): ReflectionNamedType {
30: $adapterType = ReflectionType::fromType($type);
31: assert($adapterType instanceof ReflectionNamedType);
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: /** @return false */
44: public function allowsNull(): bool
45: {
46: return $this->betterReflectionType->allowsNull();
47: }
48: }
49: