From 35bf8c2e2080c3b7fcabf67b8be64af3ef744d9b Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 3 Feb 2022 23:00:31 +0100 Subject: [PATCH] refactor: Minor SA annotations update. We are now above 97% ! --- src/Operation/Distinct.php | 9 +++++---- src/Operation/Dump.php | 2 ++ src/Operation/Duplicate.php | 9 +++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Operation/Distinct.php b/src/Operation/Distinct.php index 43f3a9f85..76e09d853 100644 --- a/src/Operation/Distinct.php +++ b/src/Operation/Distinct.php @@ -9,6 +9,7 @@ namespace loophp\collection\Operation; +use ArrayIterator; use Closure; use Generator; @@ -42,15 +43,15 @@ public function __invoke(): Closure * @return Closure(iterable): Generator */ static function (callable $accessorCallback) use ($comparatorCallback): Closure { - /** @var array $stack */ - $stack = []; + /** @var ArrayIterator $stack */ + $stack = new ArrayIterator(); $filter = (new Filter())()( /** * @param T $value * @param TKey $key */ - static function ($value, $key) use ($comparatorCallback, $accessorCallback, &$stack): bool { + static function ($value, $key) use ($comparatorCallback, $accessorCallback, $stack): bool { $matchWhenNot = static fn (): bool => true; $matcher = /** @@ -64,7 +65,7 @@ static function ($value, $key) use ($comparatorCallback, $accessorCallback, &$st return false; } - $stack[] = [$key, $value]; + $stack->append([$key, $value]); return true; } diff --git a/src/Operation/Dump.php b/src/Operation/Dump.php index 177da0fda..c6a8c64bb 100644 --- a/src/Operation/Dump.php +++ b/src/Operation/Dump.php @@ -42,6 +42,8 @@ public function __invoke(): Closure */ static fn (?Closure $callback = null): Closure => /** + * @param iterable $iterable + * * @return Generator */ static function (iterable $iterable) use ($name, $size, $callback): Generator { diff --git a/src/Operation/Duplicate.php b/src/Operation/Duplicate.php index 0348fbac4..8c501134f 100644 --- a/src/Operation/Duplicate.php +++ b/src/Operation/Duplicate.php @@ -9,6 +9,7 @@ namespace loophp\collection\Operation; +use ArrayIterator; use Closure; use Generator; @@ -42,15 +43,15 @@ public function __invoke(): Closure * @return Closure(iterable): Generator */ static function (callable $accessorCallback) use ($comparatorCallback): Closure { - /** @var array $stack */ - $stack = []; + /** @var ArrayIterator $stack */ + $stack = new ArrayIterator(); $filter = (new Filter())()( /** * @param T $value * @param TKey $key */ - static function ($value, $key) use ($comparatorCallback, $accessorCallback, &$stack): bool { + static function ($value, $key) use ($comparatorCallback, $accessorCallback, $stack): bool { $matchWhenNot = static fn (): bool => true; $matcher = /** @@ -64,7 +65,7 @@ static function ($value, $key) use ($comparatorCallback, $accessorCallback, &$st return true; } - $stack[] = [$key, $value]; + $stack->append([$key, $value]); return false; }