Skip to content

Commit d696a8e

Browse files
authored
feat: use template typehint in parameters (#7078)
1 parent 545eb69 commit d696a8e

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/Metadata/Parameters.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
*/
2323
final class Parameters implements \IteratorAggregate, \Countable
2424
{
25+
/**
26+
* @var array<int, array{0: string, 1: Parameter}>
27+
*/
2528
private array $parameters = [];
2629

2730
/**
@@ -68,7 +71,9 @@ public function add(string $key, Parameter $value): self
6871
}
6972

7073
/**
71-
* @param class-string $parameterClass
74+
* @template T of Parameter
75+
*
76+
* @param class-string<T> $parameterClass
7277
*/
7378
public function remove(string $key, string $parameterClass = QueryParameter::class): self
7479
{
@@ -84,7 +89,11 @@ public function remove(string $key, string $parameterClass = QueryParameter::cla
8489
}
8590

8691
/**
87-
* @param class-string $parameterClass
92+
* @template T of Parameter
93+
*
94+
* @param class-string<T> $parameterClass
95+
*
96+
* @return T|null
8897
*/
8998
public function get(string $key, string $parameterClass = QueryParameter::class): ?Parameter
9099
{
@@ -98,7 +107,9 @@ public function get(string $key, string $parameterClass = QueryParameter::class)
98107
}
99108

100109
/**
101-
* @param class-string $parameterClass
110+
* @template T of Parameter
111+
*
112+
* @param class-string<T> $parameterClass
102113
*/
103114
public function has(string $key, string $parameterClass = QueryParameter::class): bool
104115
{
@@ -118,7 +129,7 @@ public function count(): int
118129

119130
public function sort(): self
120131
{
121-
usort($this->parameters, fn ($a, $b): int|float => $b[1]->getPriority() - $a[1]->getPriority());
132+
usort($this->parameters, static fn (array $a, array $b): int => $b[1]->getPriority() - $a[1]->getPriority());
122133

123134
return $this;
124135
}

0 commit comments

Comments
 (0)