diff --git a/src/Type/CHANGELOG.md b/src/Type/CHANGELOG.md index cc8f9974..ae2c2dc7 100644 --- a/src/Type/CHANGELOG.md +++ b/src/Type/CHANGELOG.md @@ -8,3 +8,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## 0.3.1 - Deprecated calling `types::alias()`, `types::template()` and `types::object()` with named arguments. +- Deprecated `TypeVisitor::value()` and `DefaultVisitor::value()`. diff --git a/src/Type/DefaultTypeVisitor.php b/src/Type/DefaultTypeVisitor.php index 91a8d771..2df3e3e1 100644 --- a/src/Type/DefaultTypeVisitor.php +++ b/src/Type/DefaultTypeVisitor.php @@ -181,6 +181,9 @@ public function union(Type $self, array $types): mixed return $this->default($self); } + /** + * @deprecated will be removed in 0.4.0 + */ public function value(Type $self, Type $type): mixed { return $this->default($self); diff --git a/src/Type/Internal/ValueType.php b/src/Type/Internal/ValueType.php deleted file mode 100644 index 2684cb98..00000000 --- a/src/Type/Internal/ValueType.php +++ /dev/null @@ -1,26 +0,0 @@ - - */ -final class ValueType implements Type -{ - public function __construct( - private readonly Type $type, - ) {} - - public function accept(TypeVisitor $visitor): mixed - { - return $visitor->value($this, $this->type); - } -} diff --git a/src/Type/TypeVisitor.php b/src/Type/TypeVisitor.php index 14e2fb86..e1f2c7e7 100644 --- a/src/Type/TypeVisitor.php +++ b/src/Type/TypeVisitor.php @@ -219,6 +219,7 @@ public function truthyString(Type $self): mixed; public function union(Type $self, array $types): mixed; /** + * @deprecated will be removed in 0.4.0 * @return TReturn */ public function value(Type $self, Type $type): mixed; diff --git a/src/Type/types.php b/src/Type/types.php index 4a2b4325..ea09a8ae 100644 --- a/src/Type/types.php +++ b/src/Type/types.php @@ -427,7 +427,7 @@ public static function union(Type ...$types): Type public static function value(Type $type): Type { - return new Internal\ValueType($type); + return self::offset($type, self::key($type)); } /** diff --git a/tests/TypeStringifier/TypeStringifierTest.php b/tests/TypeStringifier/TypeStringifierTest.php index 79718c53..e6331783 100644 --- a/tests/TypeStringifier/TypeStringifierTest.php +++ b/tests/TypeStringifier/TypeStringifierTest.php @@ -125,7 +125,7 @@ public static function types(): \Generator yield [types::constant('test'), 'test']; yield [types::classConstant(types::object(\stdClass::class), 'test'), 'stdClass::test']; yield [types::key(types::list()), 'key-of']; - yield [types::value(types::list()), 'value-of']; + yield [types::value(types::list()), 'list[key-of]']; yield [types::conditional(types::arg('a'), if: types::string, then: types::int, else: types::float), '($a is string ? int : float)']; yield [types::conditional(types::template('T', types::atFunction('trim')), if: types::string, then: types::int, else: types::float), '(T@trim() is string ? int : float)']; yield [types::array(value: types::varianceAware(types::int, Variance::Covariant)), 'array'];