Skip to content

Commit

Permalink
AnyLiteralType -> LiteralType, LiteralType -> LiteralValueType
Browse files Browse the repository at this point in the history
  • Loading branch information
vudaltsov committed Feb 24, 2024
1 parent 2bd9f96 commit baa8a79
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 59 deletions.
26 changes: 0 additions & 26 deletions src/AnyLiteralType.php

This file was deleted.

12 changes: 6 additions & 6 deletions src/DefaultTypeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions src/LiteralType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
/**
* @internal
* @psalm-internal Typhoon\Type
* @template-covariant TValue of bool|int|float|string
* @implements Type<TValue>
* @template-covariant TType
* @implements Type<TType>
*/
final class LiteralType implements Type
{
/**
* @param TValue $value
* @param Type<TType> $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);
}
}
26 changes: 26 additions & 0 deletions src/LiteralValueType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Typhoon\Type;

/**
* @internal
* @psalm-internal Typhoon\Type
* @template-covariant TValue of bool|int|float|string
* @implements Type<TValue>
*/
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);
}
}
12 changes: 6 additions & 6 deletions src/TypeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<array<mixed>> $self
* @return TReturn
Expand Down Expand Up @@ -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
Expand Down
32 changes: 16 additions & 16 deletions src/types.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,6 @@ public static function alias(string $class, string $name): Type
return new AliasType($class, $name);
}

/**
* @template TType
* @param Type<TType> $type
* @return Type<TType>
*/
public static function anyLiteral(Type $type): Type
{
return new AnyLiteralType($type);
}

/**
* @param non-empty-string $name
*/
Expand Down Expand Up @@ -272,14 +262,24 @@ public static function list(Type $value = self::mixed): Type
return new ListType($value);
}

/**
* @template TType
* @param Type<TType> $type
* @return Type<TType>
*/
public static function literal(Type $type): Type
{
return new LiteralType($type);
}

/**
* @template TValue of bool|int|float|string
* @param TValue $value
* @return Type<TValue>
*/
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);
}

/**
Expand Down Expand Up @@ -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),
Expand All @@ -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),
};
Expand Down

0 comments on commit baa8a79

Please sign in to comment.