From 497e73569595e4b9c3d107d36062e866f7101584 Mon Sep 17 00:00:00 2001 From: Valentin Udaltsov Date: Fri, 23 Feb 2024 14:04:26 +0300 Subject: [PATCH] Redesign follow-up --- src/DefaultTypeVisitor.php | 2 +- src/{OffsetOfType.php => OffsetType.php} | 4 ++-- src/TypeVisitor.php | 2 +- src/types.php | 14 ++++++-------- 4 files changed, 10 insertions(+), 12 deletions(-) rename src/{OffsetOfType.php => OffsetType.php} (74%) diff --git a/src/DefaultTypeVisitor.php b/src/DefaultTypeVisitor.php index 41ebee0..9834343 100644 --- a/src/DefaultTypeVisitor.php +++ b/src/DefaultTypeVisitor.php @@ -166,7 +166,7 @@ public function objectShape(Type $type, array $properties): mixed return $this->default($type); } - public function offsetOf(Type $type, Type $innerType, Type $offset): mixed + public function offset(Type $type, Type $innerType, Type $offset): mixed { return $this->default($type); } diff --git a/src/OffsetOfType.php b/src/OffsetType.php similarity index 74% rename from src/OffsetOfType.php rename to src/OffsetType.php index 570c6ba..d635893 100644 --- a/src/OffsetOfType.php +++ b/src/OffsetType.php @@ -9,7 +9,7 @@ * @psalm-internal Typhoon\Type * @implements Type */ -final class OffsetOfType implements Type +final class OffsetType implements Type { public function __construct( private readonly Type $type, @@ -18,6 +18,6 @@ public function __construct( public function accept(TypeVisitor $visitor): mixed { - return $visitor->offsetOf($this, $this->type, $this->offset); + return $visitor->offset($this, $this->type, $this->offset); } } diff --git a/src/TypeVisitor.php b/src/TypeVisitor.php index 6e9f289..e53baa1 100644 --- a/src/TypeVisitor.php +++ b/src/TypeVisitor.php @@ -232,7 +232,7 @@ public function objectShape(Type $type, array $properties): mixed; /** * @return TReturn */ - public function offsetOf(Type $type, Type $innerType, Type $offset): mixed; + public function offset(Type $type, Type $innerType, Type $offset): mixed; /** * @param Type $type diff --git a/src/types.php b/src/types.php index f0d3417..f307247 100644 --- a/src/types.php +++ b/src/types.php @@ -348,17 +348,15 @@ public static function object(string $class, Type ...$templateArguments): Type */ public static function objectShape(array $properties = []): Type { - return new ObjectShapeType( - array_map( - static fn(Type|Property $property): Property => $property instanceof Type ? new Property($property) : $property, - $properties, - ), - ); + return new ObjectShapeType(array_map( + static fn(Type|Property $property): Property => $property instanceof Type ? new Property($property) : $property, + $properties, + )); } - public static function offsetOf(Type $type, Type $offset): Type + public static function offset(Type $type, Type $offset): Type { - return new OffsetOfType($type, $offset); + return new OffsetType($type, $offset); } /**