From 77db2cddf5d1b7718b7f041305689034144b1699 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Tue, 30 Mar 2021 08:22:17 +0200 Subject: [PATCH] refactor: Minor types fixes. --- src/Contract/Operation/Partitionable.php | 2 +- src/Iterator/ArrayCacheIterator.php | 2 -- src/Operation/Pipe.php | 10 +++++++--- src/Operation/Reverse.php | 19 +++++++++---------- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/Contract/Operation/Partitionable.php b/src/Contract/Operation/Partitionable.php index 2cdee9da3..dec1866be 100644 --- a/src/Contract/Operation/Partitionable.php +++ b/src/Contract/Operation/Partitionable.php @@ -17,7 +17,7 @@ interface Partitionable * @param callable ...$callbacks * @psalm-param callable(T, TKey):bool ...$callbacks * - * @psalm-return \loophp\collection\Collection}> + * @psalm-return \loophp\collection\Collection> */ public function partition(callable ...$callbacks): Collection; } diff --git a/src/Iterator/ArrayCacheIterator.php b/src/Iterator/ArrayCacheIterator.php index a3b0baecc..874ff083e 100644 --- a/src/Iterator/ArrayCacheIterator.php +++ b/src/Iterator/ArrayCacheIterator.php @@ -39,7 +39,6 @@ public function __construct(Iterator $iterator) */ public function current() { - /** @psalm-var array{TKey, T} $data */ $data = $this->getTupleFromCache($this->key); return $data[1]; @@ -50,7 +49,6 @@ public function current() */ public function key() { - /** @psalm-var array{TKey, T} $data */ $data = $this->getTupleFromCache($this->key); return $data[0]; diff --git a/src/Operation/Pipe.php b/src/Operation/Pipe.php index b2524bb10..d6c2c0794 100644 --- a/src/Operation/Pipe.php +++ b/src/Operation/Pipe.php @@ -8,6 +8,8 @@ use Generator; use Iterator; +use function call_user_func; + /** * @psalm-template TKey * @psalm-template TKey of array-key @@ -18,7 +20,9 @@ final class Pipe extends AbstractOperation { /** - * @psalm-return Closure(callable(Iterator): Iterator ...): Closure (Iterator): Iterator + * @psalm-return Closure(...callable(Iterator):Generator):Closure(Iterator):Iterator + * + * @return Closure (Iterator): Iterator */ public function __invoke(): Closure { @@ -38,11 +42,11 @@ static function (Iterator $iterator) use ($operations): Iterator { $callback = /** * @psalm-param Iterator $iterator - * @psalm-param callable(Iterator): Iterator $fn + * @psalm-param callable(Iterator): Iterator $callable * * @psalm-return Iterator */ - static fn (Iterator $iterator, callable $fn): Iterator => $fn($iterator); + static fn (Iterator $iterator, callable $callable): Iterator => call_user_func($callable, $iterator); return array_reduce($operations, $callback, $iterator); }; diff --git a/src/Operation/Reverse.php b/src/Operation/Reverse.php index d2ef61313..f1ffe9ee4 100644 --- a/src/Operation/Reverse.php +++ b/src/Operation/Reverse.php @@ -24,16 +24,15 @@ final class Reverse extends AbstractOperation */ public function __invoke(): Closure { - /** - * @param array $carry - * @psalm-param array $carry - * - * @param array $value - * @psalm-param array{0: TKey, 1: T} $value - * - * @psalm-return array - */ - $callback = static fn (array $carry, array $value): array => [...$value, ...$carry]; + $callback = + /** + * @psalm-param list $carry + * + * @psalm-param list $value + * + * @psalm-return list + */ + static fn (array $carry, array $value): array => [...$value, ...$carry]; /** @psalm-var Closure(Iterator): Generator $pipe */ $pipe = Pipe::of()(