From 37c6a5c3f1b6e6c39dd1b323dd3c49848f4f0415 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Sun, 30 Aug 2020 22:29:50 +0200 Subject: [PATCH] Update annotations. --- src/Contract/Collection.php | 4 +-- src/Contract/Operation/Allable.php | 2 +- src/Operation/Reduce.php | 40 ++++++++++++++++++++++-------- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/Contract/Collection.php b/src/Contract/Collection.php index 94d21f507..e619f2eee 100644 --- a/src/Contract/Collection.php +++ b/src/Contract/Collection.php @@ -65,7 +65,6 @@ use loophp\collection\Contract\Operation\Reductionable; use loophp\collection\Contract\Operation\Reverseable; use loophp\collection\Contract\Operation\RSampleable; -use loophp\collection\Contract\Operation\Runable; use loophp\collection\Contract\Operation\Scaleable; use loophp\collection\Contract\Operation\Shuffleable; use loophp\collection\Contract\Operation\Sinceable; @@ -154,7 +153,7 @@ * @template-extends Splitable * @template-extends Tailable * @template-extends Transposeable - * @template-extends Unpack + * @template-extends Unpackable * @template-extends Unpairable * @template-extends Untilable * @template-extends Unwrapable @@ -162,7 +161,6 @@ * @template-extends Wrapable * @template-extends Zipable * @template-extends \IteratorAggregate - * @template-extends Runable */ interface Collection extends Allable, diff --git a/src/Contract/Operation/Allable.php b/src/Contract/Operation/Allable.php index 7b8a40c4b..049b357c9 100644 --- a/src/Contract/Operation/Allable.php +++ b/src/Contract/Operation/Allable.php @@ -14,7 +14,7 @@ interface Allable /** * Get all items from the collection. * - * @return array + * @psalm-return array * An array containing all the elements of the collection. */ public function all(): array; diff --git a/src/Operation/Reduce.php b/src/Operation/Reduce.php index 39533c63d..addbdc5df 100644 --- a/src/Operation/Reduce.php +++ b/src/Operation/Reduce.php @@ -5,6 +5,7 @@ namespace loophp\collection\Operation; use Closure; +use Generator; use Iterator; /** @@ -14,20 +15,39 @@ */ final class Reduce extends AbstractOperation { + // phpcs:disable /** - * @psalm-param \Iterator $collection - * - * @return mixed|null - * @psalm-return T|scalar|null|\Iterator + * @psalm-return Closure(callable(T|null, T, TKey, Iterator): T): Closure(T|null): Closure(Iterator): Generator */ + // phpcs:enable public function __invoke(): Closure { - return static function (callable $callback): Closure { - return static function ($initial = null) use ($callback): Closure { - return static function (Iterator $iterator) use ($callback, $initial) { - return yield from FoldLeft::of()($callback)($initial)($iterator); - }; + return + /** + * @psalm-param callable(T|null, T, TKey, Iterator): T $callback + * + * @psalm-return Closure(T|null): Closure(Iterator): Generator + */ + static function (callable $callback): Closure { + return + /** + * @psalm-param T|null $initial + * + * @psalm-return Closure(Iterator): Generator + * + * @param mixed|null $initial + */ + static function ($initial = null) use ($callback): Closure { + return + /** + * @psalm-param Iterator $iterator + * + * @psalm-return Generator + */ + static function (Iterator $iterator) use ($callback, $initial): Generator { + return yield from FoldLeft::of()($callback)($initial)($iterator); + }; + }; }; - }; } }