diff --git a/src/OffsetType.php b/src/OffsetType.php new file mode 100644 index 0000000..4b26f53 --- /dev/null +++ b/src/OffsetType.php @@ -0,0 +1,33 @@ + + */ +final class OffsetType implements Type +{ + public readonly Type $subject; + + public readonly Type $offset; + + /** + * @internal + * @psalm-internal Typhoon\Type + */ + public function __construct( + Type $subject, + Type $offset, + ) { + $this->subject = $subject; + $this->offset = $offset; + } + + public function accept(TypeVisitor $visitor): mixed + { + return $visitor->visitOffset($this); + } +} diff --git a/src/TypeVisitor.php b/src/TypeVisitor.php index 41d5ca1..52fb73c 100644 --- a/src/TypeVisitor.php +++ b/src/TypeVisitor.php @@ -151,6 +151,9 @@ public function visitKeyOf(KeyOfType $type): mixed; /** @return TReturn */ public function visitValueOf(ValueOfType $type): mixed; + /** @return TReturn */ + public function visitOffset(OffsetType $type): mixed; + /** @return TReturn */ public function visitTemplate(TemplateType $type): mixed; diff --git a/src/types.php b/src/types.php index d5c528f..f3c8322 100644 --- a/src/types.php +++ b/src/types.php @@ -334,6 +334,11 @@ public static function valueOf(Type $type): ValueOfType return new ValueOfType($type); } + public static function offset(Type $subject, Type $offset): OffsetType + { + return new OffsetType($subject, $offset); + } + /** * @template TType * @param non-empty-string $name diff --git a/tests/PsalmTest.php b/tests/PsalmTest.php index 2fee26e..a0223a8 100644 --- a/tests/PsalmTest.php +++ b/tests/PsalmTest.php @@ -64,6 +64,7 @@ public static function extractType(Type $_type): mixed #[TestWith([__DIR__ . '/psalm/NumericType.phpt'])] #[TestWith([__DIR__ . '/psalm/ObjectShapeType.phpt'])] #[TestWith([__DIR__ . '/psalm/ObjectType.phpt'])] + #[TestWith([__DIR__ . '/psalm/OffsetType.phpt'])] #[TestWith([__DIR__ . '/psalm/ResourceType.phpt'])] #[TestWith([__DIR__ . '/psalm/ScalarType.phpt'])] #[TestWith([__DIR__ . '/psalm/StaticType.phpt'])] diff --git a/tests/psalm/OffsetType.phpt b/tests/psalm/OffsetType.phpt new file mode 100644 index 0000000..942d5ed --- /dev/null +++ b/tests/psalm/OffsetType.phpt @@ -0,0 +1,9 @@ +--FILE-- +