Skip to content

Commit

Permalink
Deprecated calling types::alias(), types::template() and types::objec…
Browse files Browse the repository at this point in the history
…t() with named arguments

Closes #15
  • Loading branch information
vudaltsov committed Mar 9, 2024
1 parent 9a52d5d commit e2ec2dd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.3.1

- Deprecated calling `types::alias()`, `types::template()` and `types::object()` with named arguments.
24 changes: 21 additions & 3 deletions types.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ enum types implements Type
*/
public static function alias(string $class, string $name, Type ...$arguments): Type
{
return new Internal\AliasType($class, $name, array_values($arguments));
if (!array_is_list($arguments)) {
trigger_deprecation('typhoon/type', '0.3.1', 'Calling %s() with named arguments is deprecated.', __METHOD__);
/** @var list<Type> */
$arguments = array_values($arguments);
}

return new Internal\AliasType($class, $name, $arguments);
}

/**
Expand Down Expand Up @@ -344,7 +350,13 @@ public static function object(string $class, Type ...$arguments): Type
return self::closure;
}

return new Internal\NamedObjectType($class, array_values($arguments));
if (!array_is_list($arguments)) {
trigger_deprecation('typhoon/type', '0.3.1', 'Calling %s() with named arguments is deprecated.', __METHOD__);
/** @var list<Type> */
$arguments = array_values($arguments);
}

return new Internal\NamedObjectType($class, $arguments);
}

/**
Expand Down Expand Up @@ -389,7 +401,13 @@ public static function prop(Type $type, bool $optional = false): Property
*/
public static function template(string $name, AtMethod|AtClass|AtFunction $declaredAt, Type ...$arguments): Type
{
return new Internal\TemplateType($name, $declaredAt, array_values($arguments));
if (!array_is_list($arguments)) {
trigger_deprecation('typhoon/type', '0.3.1', 'Calling %s() with named arguments is deprecated.', __METHOD__);
/** @var list<Type> */
$arguments = array_values($arguments);
}

return new Internal\TemplateType($name, $declaredAt, $arguments);
}

/**
Expand Down

0 comments on commit e2ec2dd

Please sign in to comment.