Skip to content

Commit

Permalink
Added arguments to alias and template
Browse files Browse the repository at this point in the history
  • Loading branch information
vudaltsov committed Feb 27, 2024
1 parent c428b79 commit 22f9af6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/AliasType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ final class AliasType implements Type
/**
* @param non-empty-string $class
* @param non-empty-string $name
* @param list<Type> $arguments
*/
public function __construct(
private readonly string $class,
private readonly string $name,
private readonly array $arguments,
) {}

public function accept(TypeVisitor $visitor): mixed
{
return $visitor->alias($this, $this->class, $this->name);
return $visitor->alias($this, $this->class, $this->name, $this->arguments);
}
}
4 changes: 2 additions & 2 deletions src/DefaultTypeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
abstract class DefaultTypeVisitor implements TypeVisitor
{
public function alias(Type $self, string $class, string $name): mixed
public function alias(Type $self, string $class, string $name, array $arguments): mixed
{
return $this->default($self);
}
Expand Down Expand Up @@ -176,7 +176,7 @@ public function string(Type $self): mixed
return $this->default($self);
}

public function template(Type $self, string $name, AtClass|AtFunction|AtMethod $declaredAt): mixed
public function template(Type $self, string $name, AtClass|AtFunction|AtMethod $declaredAt, array $arguments): mixed
{
return $this->default($self);
}
Expand Down
4 changes: 3 additions & 1 deletion src/TemplateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ final class TemplateType implements Type
{
/**
* @param non-empty-string $name
* @param list<Type> $arguments
*/
public function __construct(
private readonly string $name,
private readonly AtFunction|AtClass|AtMethod $declaredAt,
private readonly array $arguments,
) {}

public function accept(TypeVisitor $visitor): mixed
{
return $visitor->template($this, $this->name, $this->declaredAt);
return $visitor->template($this, $this->name, $this->declaredAt, $this->arguments);
}
}
6 changes: 4 additions & 2 deletions src/TypeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ interface TypeVisitor
/**
* @param non-empty-string $class
* @param non-empty-string $name
* @param list<Type> $arguments
* @return TReturn
*/
public function alias(Type $self, string $class, string $name): mixed;
public function alias(Type $self, string $class, string $name, array $arguments): mixed;

/**
* @param Type<array<mixed>> $self
Expand Down Expand Up @@ -211,9 +212,10 @@ public function string(Type $self): mixed;

/**
* @param non-empty-string $name
* @param list<Type> $arguments
* @return TReturn
*/
public function template(Type $self, string $name, AtFunction|AtClass|AtMethod $declaredAt): mixed;
public function template(Type $self, string $name, AtFunction|AtClass|AtMethod $declaredAt, array $arguments): mixed;

/**
* @param Type<truthy-string> $self
Expand Down
8 changes: 4 additions & 4 deletions src/types.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ enum types implements Type
* @param non-empty-string $class
* @param non-empty-string $name
*/
public static function alias(string $class, string $name): Type
public static function alias(string $class, string $name, Type ...$arguments): Type
{
return new AliasType($class, $name);
return new AliasType($class, $name, array_values($arguments));
}

/**
Expand Down Expand Up @@ -393,9 +393,9 @@ public static function prop(Type $type, bool $optional = false): Property
/**
* @param non-empty-string $name
*/
public static function template(string $name, AtMethod|AtClass|AtFunction $declaredAt): Type
public static function template(string $name, AtMethod|AtClass|AtFunction $declaredAt, Type ...$arguments): Type
{
return new TemplateType($name, $declaredAt);
return new TemplateType($name, $declaredAt, array_values($arguments));
}

/**
Expand Down

0 comments on commit 22f9af6

Please sign in to comment.