Skip to content

Commit 66ca4a4

Browse files
committed
Add template params to CallbackIterator
1 parent 8e003c0 commit 66ca4a4

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/Model/CallbackIterator.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,24 @@
2727
* Iterator to apply a callback before returning an element
2828
*
2929
* @internal
30+
*
31+
* @template TKey
32+
* @template TValue
33+
* @template TCallbackValue
34+
* @template-implements Iterator<TKey, TCallbackValue>
3035
*/
3136
class CallbackIterator implements Iterator
3237
{
33-
/** @var Closure */
38+
/** @var Closure(TValue, TKey): TCallbackValue */
3439
private $callback;
3540

36-
/** @var Iterator */
41+
/** @var Iterator<TKey, TValue> */
3742
private $iterator;
3843

44+
/**
45+
* @param Traversable<TKey, TValue> $traversable
46+
* @param Closure(TValue, TKey): TCallbackValue $callback
47+
*/
3948
public function __construct(Traversable $traversable, Closure $callback)
4049
{
4150
$this->iterator = $traversable instanceof Iterator ? $traversable : new IteratorIterator($traversable);
@@ -44,7 +53,7 @@ public function __construct(Traversable $traversable, Closure $callback)
4453

4554
/**
4655
* @see https://php.net/iterator.current
47-
* @return mixed
56+
* @return TCallbackValue
4857
*/
4958
#[ReturnTypeWillChange]
5059
public function current()
@@ -54,7 +63,7 @@ public function current()
5463

5564
/**
5665
* @see https://php.net/iterator.key
57-
* @return mixed
66+
* @return TKey
5867
*/
5968
#[ReturnTypeWillChange]
6069
public function key()

0 commit comments

Comments
 (0)