From 5928c82dda3df6f437174edc0c2f4f6653f412a5 Mon Sep 17 00:00:00 2001 From: Valentin Udaltsov Date: Tue, 27 Feb 2024 12:38:21 +0300 Subject: [PATCH] VarianceAwareType as type decorator, not a standalone type --- src/DefaultTypeVisitor.php | 5 ----- src/NamedObjectType.php | 2 +- src/TypeVisitor.php | 7 +------ src/VarianceAwareType.php | 15 ++++----------- src/types.php | 12 +----------- 5 files changed, 7 insertions(+), 34 deletions(-) diff --git a/src/DefaultTypeVisitor.php b/src/DefaultTypeVisitor.php index 3d7c772..3d7b706 100644 --- a/src/DefaultTypeVisitor.php +++ b/src/DefaultTypeVisitor.php @@ -196,11 +196,6 @@ public function value(Type $self, Type $type): mixed return $this->default($self); } - public function varianceAware(Type $self, Type $type, Variance $variance): mixed - { - return $this->default($self); - } - public function void(Type $self): mixed { return $this->default($self); diff --git a/src/NamedObjectType.php b/src/NamedObjectType.php index 9967aa2..4089e3a 100644 --- a/src/NamedObjectType.php +++ b/src/NamedObjectType.php @@ -13,7 +13,7 @@ final class NamedObjectType implements Type { /** * @param non-empty-string $class - * @param list $templateArguments + * @param list $templateArguments */ public function __construct( private readonly string $class, diff --git a/src/TypeVisitor.php b/src/TypeVisitor.php index 8627eba..c6f83ba 100644 --- a/src/TypeVisitor.php +++ b/src/TypeVisitor.php @@ -151,7 +151,7 @@ public function namedClassString(Type $self, Type $object): mixed; /** * @param Type $self * @param non-empty-string $class - * @param list $templateArguments + * @param list $templateArguments * @return TReturn */ public function namedObject(Type $self, string $class, array $templateArguments): mixed; @@ -232,11 +232,6 @@ public function union(Type $self, array $types): mixed; */ public function value(Type $self, Type $type): mixed; - /** - * @return TReturn - */ - public function varianceAware(Type $self, Type $type, Variance $variance): mixed; - /** * @param Type $self * @return TReturn diff --git a/src/VarianceAwareType.php b/src/VarianceAwareType.php index 047294f..966271b 100644 --- a/src/VarianceAwareType.php +++ b/src/VarianceAwareType.php @@ -5,23 +5,16 @@ namespace Typhoon\Type; /** - * @internal - * @psalm-internal Typhoon\Type + * @api * @template-covariant TType - * @implements Type */ -final class VarianceAwareType implements Type +final class VarianceAwareType { /** * @param Type $type */ public function __construct( - private readonly Type $type, - private readonly Variance $variance, + public readonly Type $type, + public readonly Variance $variance, ) {} - - public function accept(TypeVisitor $visitor): mixed - { - return $visitor->varianceAware($this, $this->type, $this->variance); - } } diff --git a/src/types.php b/src/types.php index 7cf06c8..76e21ba 100644 --- a/src/types.php +++ b/src/types.php @@ -344,7 +344,7 @@ public static function nullable(Type $type): Type * @param class-string|non-empty-string $class * @return ($class is class-string ? Type : Type) */ - public static function object(string $class, Type ...$templateArguments): Type + public static function object(string $class, Type|VarianceAwareType ...$templateArguments): Type { if ($class === \Closure::class && $templateArguments === []) { return self::closure; @@ -421,16 +421,6 @@ public static function value(Type $type): Type return new ValueType($type); } - /** - * @template TType - * @param Type $type - * @return Type - */ - public static function varianceAware(Type $type, Variance $variance): Type - { - return new VarianceAwareType($type, $variance); - } - public function accept(TypeVisitor $visitor): mixed { return match ($this) {