diff --git a/src/AnyLiteralType.php b/src/AnyLiteralType.php deleted file mode 100644 index 3d770f8..0000000 --- a/src/AnyLiteralType.php +++ /dev/null @@ -1,26 +0,0 @@ - - */ -final class AnyLiteralType implements Type -{ - /** - * @param Type $type - */ - public function __construct( - private readonly Type $type, - ) {} - - public function accept(TypeVisitor $visitor): mixed - { - return $visitor->anyLiteral($this, $this->type); - } -} diff --git a/src/DefaultTypeVisitor.php b/src/DefaultTypeVisitor.php index 1cb31b2..7b1568f 100644 --- a/src/DefaultTypeVisitor.php +++ b/src/DefaultTypeVisitor.php @@ -16,11 +16,6 @@ public function alias(Type $self, string $class, string $name): mixed return $this->default($self); } - public function anyLiteral(Type $self, Type $type): mixed - { - return $this->default($self); - } - public function array(Type $self, Type $key, Type $value): mixed { return $this->default($self); @@ -111,7 +106,12 @@ public function list(Type $self, Type $value): mixed return $this->default($self); } - public function literal(Type $self, float|bool|int|string $value): mixed + public function literal(Type $self, Type $type): mixed + { + return $this->default($self); + } + + public function literalValue(Type $self, float|bool|int|string $value): mixed { return $this->default($self); } diff --git a/src/LiteralType.php b/src/LiteralType.php index 604c08d..610090b 100644 --- a/src/LiteralType.php +++ b/src/LiteralType.php @@ -7,20 +7,20 @@ /** * @internal * @psalm-internal Typhoon\Type - * @template-covariant TValue of bool|int|float|string - * @implements Type + * @template-covariant TType + * @implements Type */ final class LiteralType implements Type { /** - * @param TValue $value + * @param Type $type */ public function __construct( - private readonly bool|int|float|string $value, + private readonly Type $type, ) {} public function accept(TypeVisitor $visitor): mixed { - return $visitor->literal($this, $this->value); + return $visitor->literal($this, $this->type); } } diff --git a/src/LiteralValueType.php b/src/LiteralValueType.php new file mode 100644 index 0000000..6695050 --- /dev/null +++ b/src/LiteralValueType.php @@ -0,0 +1,26 @@ + + */ +final class LiteralValueType implements Type +{ + /** + * @param TValue $value + */ + public function __construct( + private readonly bool|int|float|string $value, + ) {} + + public function accept(TypeVisitor $visitor): mixed + { + return $visitor->literalValue($this, $this->value); + } +} diff --git a/src/TypeVisitor.php b/src/TypeVisitor.php index b58f58b..c63b5b7 100644 --- a/src/TypeVisitor.php +++ b/src/TypeVisitor.php @@ -17,11 +17,6 @@ interface TypeVisitor */ public function alias(Type $self, string $class, string $name): mixed; - /** - * @return TReturn - */ - public function anyLiteral(Type $self, Type $type): mixed; - /** * @param Type> $self * @return TReturn @@ -135,7 +130,12 @@ public function list(Type $self, Type $value): mixed; /** * @return TReturn */ - public function literal(Type $self, bool|int|float|string $value): mixed; + public function literal(Type $self, Type $type): mixed; + + /** + * @return TReturn + */ + public function literalValue(Type $self, bool|int|float|string $value): mixed; /** * @return TReturn diff --git a/src/types.php b/src/types.php index ad830a2..9cbf03c 100644 --- a/src/types.php +++ b/src/types.php @@ -49,16 +49,6 @@ public static function alias(string $class, string $name): Type return new AliasType($class, $name); } - /** - * @template TType - * @param Type $type - * @return Type - */ - public static function anyLiteral(Type $type): Type - { - return new AnyLiteralType($type); - } - /** * @param non-empty-string $name */ @@ -272,14 +262,24 @@ public static function list(Type $value = self::mixed): Type return new ListType($value); } + /** + * @template TType + * @param Type $type + * @return Type + */ + public static function literal(Type $type): Type + { + return new LiteralType($type); + } + /** * @template TValue of bool|int|float|string * @param TValue $value * @return Type */ - public static function literal(bool|int|float|string $value): Type + public static function literalValue(bool|int|float|string $value): Type { - return new LiteralType($value); + return new LiteralValueType($value); } /** @@ -411,12 +411,12 @@ public function accept(TypeVisitor $visitor): mixed self::callable => $visitor->callable($this, [], self::mixed), self::classString => $visitor->classString($this), self::closure => $visitor->closure($this, [], types::mixed), - self::false => $visitor->literal($this, false), + self::false => $visitor->literalValue($this, false), self::float => $visitor->float($this), self::int => $visitor->int($this), self::iterable => $visitor->iterable($this, self::mixed, self::mixed), - self::literalInt => $visitor->anyLiteral($this, self::int), - self::literalString => $visitor->anyLiteral($this, self::string), + self::literalInt => $visitor->literal($this, self::int), + self::literalString => $visitor->literal($this, self::string), self::mixed => $visitor->mixed($this), self::negativeInt => $visitor->intRange($this, null, -1), self::never => $visitor->never($this), @@ -431,7 +431,7 @@ public function accept(TypeVisitor $visitor): mixed self::resource => $visitor->resource($this), self::scalar => $visitor->union($this, [self::bool, self::int, self::float, self::string]), self::string => $visitor->string($this), - self::true => $visitor->literal($this, true), + self::true => $visitor->literalValue($this, true), self::truthyString => $visitor->truthyString($this), self::void => $visitor->void($this), };