From 82fcea1ef9b2279123bd1f58f7087465e36b90ff Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Mon, 31 Jan 2022 12:38:34 +0100 Subject: [PATCH] refactor: Use `new` keyword on some operations. (#231) --- phpstan-baseline.neon | 10 ---------- phpstan-unsupported-baseline.neon | 6 ------ phpstan.neon.dist | 1 - src/Contract/Operation/Mapable.php | 6 ++---- src/Contract/Operation/ScanLeft1able.php | 6 ++---- src/Contract/Operation/ScanLeftable.php | 9 +++------ src/Contract/Operation/ScanRight1able.php | 6 ++---- src/Contract/Operation/ScanRightable.php | 9 +++------ src/Contract/Operation/Unpackable.php | 7 ++----- src/Operation/AsyncMap.php | 2 +- src/Operation/AsyncMapN.php | 2 +- src/Operation/Chunk.php | 2 +- src/Operation/Collapse.php | 2 +- src/Operation/Column.php | 8 ++++---- src/Operation/Combine.php | 4 ++-- src/Operation/Contains.php | 2 +- src/Operation/Current.php | 4 ++-- src/Operation/Every.php | 10 +++++----- src/Operation/Explode.php | 2 +- src/Operation/Find.php | 6 +++--- src/Operation/FlatMap.php | 6 +++--- src/Operation/FoldLeft.php | 6 +++--- src/Operation/FoldLeft1.php | 6 +++--- src/Operation/FoldRight.php | 6 +++--- src/Operation/FoldRight1.php | 6 +++--- src/Operation/Get.php | 6 +++--- src/Operation/GroupBy.php | 6 +++--- src/Operation/Has.php | 2 +- src/Operation/IfThenElse.php | 2 +- src/Operation/Implode.php | 8 ++++---- src/Operation/Key.php | 6 +++--- src/Operation/Map.php | 2 +- src/Operation/MatchOne.php | 10 +++++----- src/Operation/Nth.php | 6 +++--- src/Operation/Product.php | 2 +- src/Operation/Random.php | 6 +++--- src/Operation/Reduce.php | 4 ++-- src/Operation/Scale.php | 2 +- src/Operation/ScanLeft.php | 8 ++++---- src/Operation/ScanLeft1.php | 10 +++++----- src/Operation/ScanRight.php | 12 ++++++------ src/Operation/ScanRight1.php | 10 +++++----- src/Operation/Slice.php | 6 +++--- src/Operation/Tails.php | 4 ++-- src/Operation/Unpack.php | 9 +++------ src/Operation/Window.php | 2 +- tests/static-analysis/map.php | 12 ++++++++++-- 47 files changed, 121 insertions(+), 148 deletions(-) delete mode 100644 phpstan-unsupported-baseline.neon diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 5ea98e62f..1048641c9 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,15 +1,5 @@ parameters: ignoreErrors: - - - message: "#^Method loophp\\\\collection\\\\Collection\\:\\:partition\\(\\) should return loophp\\\\collection\\\\Contract\\\\Collection\\\\> but returns loophp\\\\collection\\\\Contract\\\\Collection\\\\>\\.$#" - count: 1 - path: src/Collection.php - - - - message: "#^Method loophp\\\\collection\\\\Collection\\:\\:span\\(\\) should return loophp\\\\collection\\\\Contract\\\\Collection\\\\> but returns loophp\\\\collection\\\\Contract\\\\Collection\\\\>\\.$#" - count: 1 - path: src/Collection.php - - message: "#^Template type NewT of method loophp\\\\collection\\\\Operation\\\\Associate\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" count: 1 diff --git a/phpstan-unsupported-baseline.neon b/phpstan-unsupported-baseline.neon deleted file mode 100644 index fa2c0b6cd..000000000 --- a/phpstan-unsupported-baseline.neon +++ /dev/null @@ -1,6 +0,0 @@ -parameters: - ignoreErrors: - - - message: "#^Generic type loophp\\\\collection\\\\Contract\\\\Operation\\\\Unpackable\\\\> in PHPDoc tag @extends does not specify all template types of interface loophp\\\\collection\\\\Contract\\\\Operation\\\\Unpackable\\: TKey, T, NewTKey, NewT$#" - count: 1 - path: src/Contract/Collection.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist index e3884c273..0902fd458 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,4 +2,3 @@ parameters: reportUnmatchedIgnoredErrors: true includes: - phpstan-baseline.neon - - phpstan-unsupported-baseline.neon diff --git a/src/Contract/Operation/Mapable.php b/src/Contract/Operation/Mapable.php index 1c9b49e81..f2ffa5cb7 100644 --- a/src/Contract/Operation/Mapable.php +++ b/src/Contract/Operation/Mapable.php @@ -23,11 +23,9 @@ interface Mapable * * @see https://loophp-collection.readthedocs.io/en/stable/pages/api.html#map * - * @template V + * @param callable(T=, TKey=, Iterator=): mixed $callback * - * @param callable(T=, TKey=, Iterator=): V $callback - * - * @return Collection + * @return Collection */ public function map(callable $callback): Collection; } diff --git a/src/Contract/Operation/ScanLeft1able.php b/src/Contract/Operation/ScanLeft1able.php index 6df975c88..fa601a695 100644 --- a/src/Contract/Operation/ScanLeft1able.php +++ b/src/Contract/Operation/ScanLeft1able.php @@ -25,11 +25,9 @@ interface ScanLeft1able * * @see https://loophp-collection.readthedocs.io/en/stable/pages/api.html#scanleft1 * - * @template V + * @param callable(T|mixed, T, TKey, Iterator): mixed $callback * - * @param callable(T|V, T, TKey, Iterator): V $callback - * - * @return Collection + * @return Collection */ public function scanLeft1(callable $callback): Collection; } diff --git a/src/Contract/Operation/ScanLeftable.php b/src/Contract/Operation/ScanLeftable.php index 8e581ccb8..aa8df4a41 100644 --- a/src/Contract/Operation/ScanLeftable.php +++ b/src/Contract/Operation/ScanLeftable.php @@ -25,13 +25,10 @@ interface ScanLeftable * * @see https://loophp-collection.readthedocs.io/en/stable/pages/api.html#scanleft * - * @template V - * @template W + * @param callable(mixed=, T=, TKey=, Iterator=): mixed $callback + * @param mixed $initial * - * @param callable((V|W)=, T=, TKey=, Iterator=): W $callback - * @param V $initial - * - * @return Collection + * @return Collection */ public function scanLeft(callable $callback, $initial = null): Collection; } diff --git a/src/Contract/Operation/ScanRight1able.php b/src/Contract/Operation/ScanRight1able.php index 92a7b4f40..7ac01af1d 100644 --- a/src/Contract/Operation/ScanRight1able.php +++ b/src/Contract/Operation/ScanRight1able.php @@ -25,11 +25,9 @@ interface ScanRight1able * * @see https://loophp-collection.readthedocs.io/en/stable/pages/api.html#scanright1 * - * @template V + * @param callable(T|mixed, T, TKey, Iterator): mixed $callback * - * @param callable(T|V, T, TKey, Iterator): V $callback - * - * @return Collection + * @return Collection */ public function scanRight1(callable $callback): Collection; } diff --git a/src/Contract/Operation/ScanRightable.php b/src/Contract/Operation/ScanRightable.php index 911c3517d..c2a04f414 100644 --- a/src/Contract/Operation/ScanRightable.php +++ b/src/Contract/Operation/ScanRightable.php @@ -25,13 +25,10 @@ interface ScanRightable * * @see https://loophp-collection.readthedocs.io/en/stable/pages/api.html#scanright * - * @template V - * @template W + * @param callable(mixed=, T=, TKey=, Iterator=): mixed $callback + * @param mixed $initial * - * @param callable((V|W)=, T=, TKey=, Iterator=): W $callback - * @param V $initial - * - * @return Collection + * @return Collection */ public function scanRight(callable $callback, $initial = null): Collection; } diff --git a/src/Contract/Operation/Unpackable.php b/src/Contract/Operation/Unpackable.php index 09500da8d..e4cb4358b 100644 --- a/src/Contract/Operation/Unpackable.php +++ b/src/Contract/Operation/Unpackable.php @@ -13,10 +13,7 @@ /** * @template TKey - * @template T of array{0: NewTKey, 1: NewT} - * - * @template NewTKey - * @template NewT + * @template T */ interface Unpackable { @@ -25,7 +22,7 @@ interface Unpackable * * @see https://loophp-collection.readthedocs.io/en/stable/pages/api.html#unpack * - * @return Collection + * @return Collection */ public function unpack(): Collection; } diff --git a/src/Operation/AsyncMap.php b/src/Operation/AsyncMap.php index 444e964e7..602bb3fb8 100644 --- a/src/Operation/AsyncMap.php +++ b/src/Operation/AsyncMap.php @@ -64,7 +64,7 @@ static function (Iterator $iterator) use ($callback): Generator { */ static fn (array $value): array => [$value[0], $callback($value[1], $value[0])]; - $iter = map(fromIterable(Pack::of()($iterator)), new LocalSemaphore(32), parallel($parallelCallBack)); + $iter = map(fromIterable((new Pack())()($iterator)), new LocalSemaphore(32), parallel($parallelCallBack)); while (wait($iter->advance())) { /** @var array{0: TKey, 1: V} $item */ diff --git a/src/Operation/AsyncMapN.php b/src/Operation/AsyncMapN.php index 5e126da97..182630c99 100644 --- a/src/Operation/AsyncMapN.php +++ b/src/Operation/AsyncMapN.php @@ -77,7 +77,7 @@ static function (Iterator $iterator) use ($callbacks): Generator { */ static fn (array $value): array => [$value[0], array_reduce($callbacks, $callbackFactory($value[0]), $value[1])]; - $iter = map(fromIterable(Pack::of()($iterator)), new LocalSemaphore(32), parallel($callback)); + $iter = map(fromIterable((new Pack())()($iterator)), new LocalSemaphore(32), parallel($callback)); while (wait($iter->advance())) { /** @var array{0: mixed, 1: mixed} $item */ diff --git a/src/Operation/Chunk.php b/src/Operation/Chunk.php index 738fa3ffb..34111c473 100644 --- a/src/Operation/Chunk.php +++ b/src/Operation/Chunk.php @@ -43,7 +43,7 @@ public function __invoke(): Closure */ static function (Iterator $iterator) use ($sizes): Generator { /** @var Iterator $sizesIterator */ - $sizesIterator = Cycle::of()(new ArrayIterator($sizes)); + $sizesIterator = (new Cycle())()(new ArrayIterator($sizes)); $values = []; diff --git a/src/Operation/Collapse.php b/src/Operation/Collapse.php index eb7ceb6e2..0d9efd03b 100644 --- a/src/Operation/Collapse.php +++ b/src/Operation/Collapse.php @@ -37,7 +37,7 @@ public function __invoke(): Closure static fn ($value): bool => is_iterable($value); /** @var Closure(Iterator)>): Generator $pipe */ - $pipe = Pipe::of()( + $pipe = (new Pipe())()( (new Filter())()($filterCallback), (new Flatten())()(1), ); diff --git a/src/Operation/Column.php b/src/Operation/Column.php index 3dd519780..d28bf9889 100644 --- a/src/Operation/Column.php +++ b/src/Operation/Column.php @@ -48,11 +48,11 @@ static function ($column): Closure { static fn ($value, $key, Iterator $iterator): bool => $key === $column; /** @var Closure(Iterator): Generator $pipe */ - $pipe = Pipe::of()( - Transpose::of(), + $pipe = (new Pipe())()( + (new Transpose())(), (new Filter())()($filterCallbackBuilder($column)), - Head::of(), - Flatten::of()(1) + (new Head())(), + (new Flatten())()(1) ); // Point free style. diff --git a/src/Operation/Combine.php b/src/Operation/Combine.php index 6c0afe86e..ee4d65b07 100644 --- a/src/Operation/Combine.php +++ b/src/Operation/Combine.php @@ -56,8 +56,8 @@ static function (...$keys): Closure { /** @var Closure(Iterator): Generator $pipe */ $pipe = Pipe::of()( $buildMultipleIterable($keys), - Flatten::of()(1), - Pair::of(), + (new Flatten())()(1), + (new Pair())(), ); // Point free style. diff --git a/src/Operation/Contains.php b/src/Operation/Contains.php index 1cf1d7a6e..7598d0fc0 100644 --- a/src/Operation/Contains.php +++ b/src/Operation/Contains.php @@ -46,7 +46,7 @@ static function (...$values): Closure { static fn ($right): bool => $left === $right; /** @var Closure(Iterator): Generator $matchOne */ - $matchOne = MatchOne::of()(static fn (): bool => true)(...array_map($callback, $values)); + $matchOne = (new MatchOne())()(static fn (): bool => true)(...array_map($callback, $values)); // Point free style. return $matchOne; diff --git a/src/Operation/Current.php b/src/Operation/Current.php index 614590f99..fb673c704 100644 --- a/src/Operation/Current.php +++ b/src/Operation/Current.php @@ -44,9 +44,9 @@ public function __invoke(): Closure */ static function ($default) use ($index): Closure { /** @var Closure(Iterator): Generator $pipe */ - $pipe = Pipe::of()( + $pipe = (new Pipe())()( (new Normalize())(), - Get::of()($index)($default) + (new Get())()($index)($default) ); // Point free style. diff --git a/src/Operation/Every.php b/src/Operation/Every.php index 2e7b7269e..3724908b2 100644 --- a/src/Operation/Every.php +++ b/src/Operation/Every.php @@ -80,11 +80,11 @@ static function (callable ...$callbacks) use ($matchers): Closure { static fn ($value, $key, Iterator $iterator): bool => $reducer1($value, $key, $iterator) !== $reducer2($value, $key, $iterator); /** @var Closure(Iterator): Generator $pipe */ - $pipe = Pipe::of()( - Map::of()($mapCallback($callbackReducer($callbacks))($callbackReducer($matchers))), - DropWhile::of()(static fn (bool $value): bool => $value), - Append::of()(true), - Head::of(), + $pipe = (new Pipe())()( + (new Map())()($mapCallback($callbackReducer($callbacks))($callbackReducer($matchers))), + (new DropWhile())()(static fn (bool $value): bool => $value), + (new Append())()(true), + (new Head())(), ); // Point free style. diff --git a/src/Operation/Explode.php b/src/Operation/Explode.php index 27a3d1979..2f6f7477a 100644 --- a/src/Operation/Explode.php +++ b/src/Operation/Explode.php @@ -37,7 +37,7 @@ public function __invoke(): Closure */ static function (...$explodes): Closure { /** @var Closure(Iterator): Generator> $split */ - $split = Split::of()(Splitable::REMOVE)( + $split = (new Split())()(Splitable::REMOVE)( ...array_map( /** * @param T $explode diff --git a/src/Operation/Find.php b/src/Operation/Find.php index b316aee42..305112742 100644 --- a/src/Operation/Find.php +++ b/src/Operation/Find.php @@ -46,10 +46,10 @@ public function __invoke(): Closure */ static function (callable ...$callbacks) use ($default): Closure { /** @var Closure(Iterator): Generator $pipe */ - $pipe = Pipe::of()( + $pipe = (new Pipe())()( (new Filter())()(...$callbacks), - Append::of()($default), - Head::of(), + (new Append())()($default), + (new Head())(), ); // Point free style. diff --git a/src/Operation/FlatMap.php b/src/Operation/FlatMap.php index f8df891d2..2f45d170b 100644 --- a/src/Operation/FlatMap.php +++ b/src/Operation/FlatMap.php @@ -39,9 +39,9 @@ public function __invoke(): Closure */ static function (callable $callback): Closure { /** @var Closure(Iterator): Generator $flatMap */ - $flatMap = Pipe::of()( - Map::of()($callback), - Flatten::of()(1) + $flatMap = (new Pipe())()( + (new Map())()($callback), + (new Flatten())()(1) ); // Point free style diff --git a/src/Operation/FoldLeft.php b/src/Operation/FoldLeft.php index 34238a764..deb9b7e8e 100644 --- a/src/Operation/FoldLeft.php +++ b/src/Operation/FoldLeft.php @@ -44,9 +44,9 @@ public function __invoke(): Closure */ static function ($initial = null) use ($callback): Closure { /** @var Closure(Iterator): Generator $pipe */ - $pipe = Pipe::of()( - ScanLeft::of()($callback)($initial), - Last::of() + $pipe = (new Pipe())()( + (new ScanLeft())()($callback)($initial), + (new Last())() ); // Point free style. diff --git a/src/Operation/FoldLeft1.php b/src/Operation/FoldLeft1.php index 88eced14c..0e67d3ed5 100644 --- a/src/Operation/FoldLeft1.php +++ b/src/Operation/FoldLeft1.php @@ -38,9 +38,9 @@ public function __invoke(): Closure */ static function (callable $callback): Closure { /** @var Closure(Iterator):(Generator) $pipe */ - $pipe = Pipe::of()( - ScanLeft1::of()($callback), - Last::of() + $pipe = (new Pipe())()( + (new ScanLeft1())()($callback), + (new Last())() ); // Point free style. diff --git a/src/Operation/FoldRight.php b/src/Operation/FoldRight.php index 1c66c68a6..17ecfc084 100644 --- a/src/Operation/FoldRight.php +++ b/src/Operation/FoldRight.php @@ -38,9 +38,9 @@ public function __invoke(): Closure */ static fn (callable $callback): Closure => static function ($initial = null) use ($callback): Closure { /** @var Closure(Iterator): Generator $pipe */ - $pipe = Pipe::of()( - ScanRight::of()($callback)($initial), - Head::of() + $pipe = (new Pipe())()( + (new ScanRight())()($callback)($initial), + (new Head())() ); // Point free style. diff --git a/src/Operation/FoldRight1.php b/src/Operation/FoldRight1.php index 7eb3d840a..d2a339e4c 100644 --- a/src/Operation/FoldRight1.php +++ b/src/Operation/FoldRight1.php @@ -38,9 +38,9 @@ public function __invoke(): Closure */ static function (callable $callback): Closure { /** @var Closure(Iterator):(Generator) $pipe */ - $pipe = Pipe::of()( - ScanRight1::of()($callback), - Head::of() + $pipe = (new Pipe())()( + (new ScanRight1())()($callback), + (new Head())() ); // Point free style. diff --git a/src/Operation/Get.php b/src/Operation/Get.php index 8108d9919..6cff89b6e 100644 --- a/src/Operation/Get.php +++ b/src/Operation/Get.php @@ -51,10 +51,10 @@ static function ($default) use ($keyToGet): Closure { static fn ($value, $key): bool => $key === $keyToGet; /** @var Closure(Iterator): (Generator) $pipe */ - $pipe = Pipe::of()( + $pipe = (new Pipe())()( (new Filter())()($filterCallback), - Append::of()($default), - Head::of() + (new Append())()($default), + (new Head())() ); // Point free style. diff --git a/src/Operation/GroupBy.php b/src/Operation/GroupBy.php index 4dbf63a86..2ed7d7aa8 100644 --- a/src/Operation/GroupBy.php +++ b/src/Operation/GroupBy.php @@ -60,9 +60,9 @@ static function (array $collect, $value, $key) use ($callback): array { }; /** @var Closure(Iterator): Generator> $pipe */ - $pipe = Pipe::of()( - Reduce::of()($reducerFactory($callable))([]), - Flatten::of()(1) + $pipe = (new Pipe())()( + (new Reduce())()($reducerFactory($callable))([]), + (new Flatten())()(1) ); // Point free style. diff --git a/src/Operation/Has.php b/src/Operation/Has.php index 056bfa649..326acd26c 100644 --- a/src/Operation/Has.php +++ b/src/Operation/Has.php @@ -38,7 +38,7 @@ public function __invoke(): Closure */ static function (callable ...$callbacks): Closure { /** @var Closure(Iterator): Generator $pipe */ - $pipe = MatchOne::of()(static fn (): bool => true)( + $pipe = (new MatchOne())()(static fn (): bool => true)( ...array_map( static fn (callable $callback): callable => /** diff --git a/src/Operation/IfThenElse.php b/src/Operation/IfThenElse.php index 5828b9ad1..c34d76943 100644 --- a/src/Operation/IfThenElse.php +++ b/src/Operation/IfThenElse.php @@ -50,7 +50,7 @@ public function __invoke(): Closure */ static function (callable $else) use ($condition, $then): Closure { /** @var Closure(Iterator): Generator $map */ - $map = Map::of()( + $map = (new Map())()( /** * @param T $value * @param TKey $key diff --git a/src/Operation/Implode.php b/src/Operation/Implode.php index eacf6732f..055ddd86a 100644 --- a/src/Operation/Implode.php +++ b/src/Operation/Implode.php @@ -42,10 +42,10 @@ static function (string $glue): Closure { static fn (string $carry, $item): string => $carry .= $item; /** @var Closure(Iterator): Generator $pipe */ - $pipe = Pipe::of()( - Intersperse::of()($glue)(1)(0), - Drop::of()(1), - Reduce::of()($reducer)('') + $pipe = (new Pipe())()( + (new Intersperse())()($glue)(1)(0), + (new Drop())()(1), + (new Reduce())()($reducer)('') ); // Point free style. diff --git a/src/Operation/Key.php b/src/Operation/Key.php index 7289e274f..9cd7a4628 100644 --- a/src/Operation/Key.php +++ b/src/Operation/Key.php @@ -34,9 +34,9 @@ public function __invoke(): Closure */ static function (int $index): Closure { /** @var Closure(Iterator): Generator $pipe */ - $pipe = Pipe::of()( - Limit::of()(1)($index), - Flip::of() + $pipe = (new Pipe())()( + (new Limit())()(1)($index), + (new Flip())() ); // Point free style. diff --git a/src/Operation/Map.php b/src/Operation/Map.php index ab10965df..2da01a9ba 100644 --- a/src/Operation/Map.php +++ b/src/Operation/Map.php @@ -28,7 +28,7 @@ final class Map extends AbstractOperation * * @template V * - * @return Closure(callable(T=, TKey=, Iterator=): V): Closure(Iterator): Generator + * @return Closure(callable(T=, TKey=, Iterator=): mixed): Closure(Iterator): Generator */ public function __invoke(): Closure { diff --git a/src/Operation/MatchOne.php b/src/Operation/MatchOne.php index 2b1fbd50b..d53ae5157 100644 --- a/src/Operation/MatchOne.php +++ b/src/Operation/MatchOne.php @@ -46,8 +46,8 @@ static function (callable ...$matchers): Closure { */ static function (callable ...$callbacks) use ($matchers): Closure { /** @var Closure(Iterator): Generator $pipe */ - $pipe = Pipe::of()( - Map::of()( + $pipe = (new Pipe())()( + (new Map())()( /** * @param T $value * @param TKey $key @@ -55,9 +55,9 @@ static function (callable ...$callbacks) use ($matchers): Closure { */ static fn ($value, $key, Iterator $iterator): bool => CallbacksArrayReducer::or()($callbacks, $value, $key, $iterator) === CallbacksArrayReducer::or()($matchers, $value, $key, $iterator) ), - DropWhile::of()(static fn (bool $value): bool => !$value), - Append::of()(false), - Head::of() + (new DropWhile())()(static fn (bool $value): bool => !$value), + (new Append())()(false), + (new Head())() ); // Point free style. diff --git a/src/Operation/Nth.php b/src/Operation/Nth.php index 899b66540..61724bb83 100644 --- a/src/Operation/Nth.php +++ b/src/Operation/Nth.php @@ -44,10 +44,10 @@ static function (int $offset) use ($step): Closure { static fn (array $value, int $key): bool => (($key % $step) === $offset); /** @var Closure(Iterator): Generator $pipe */ - $pipe = Pipe::of()( - Pack::of(), + $pipe = (new Pipe())()( + (new Pack())(), (new Filter())()($filterCallback), - Unpack::of() + (new Unpack())() ); // Point free style. diff --git a/src/Operation/Product.php b/src/Operation/Product.php index d020ee1b9..dd086237c 100644 --- a/src/Operation/Product.php +++ b/src/Operation/Product.php @@ -39,7 +39,7 @@ public function __invoke(): Closure */ static function (iterable ...$iterables): Closure { /** @var Closure(Iterator): Generator> $pipe */ - $pipe = Pipe::of()( + $pipe = (new Pipe())()( ( /** * @param list> $iterables diff --git a/src/Operation/Random.php b/src/Operation/Random.php index 2c620968d..4fe7d0ace 100644 --- a/src/Operation/Random.php +++ b/src/Operation/Random.php @@ -39,9 +39,9 @@ static function (int $seed): Closure { */ static function (int $size) use ($seed): Closure { /** @var Closure(Iterator): Generator $pipe */ - $pipe = Pipe::of()( - Shuffle::of()($seed), - Limit::of()($size)(0) + $pipe = (new Pipe())()( + (new Shuffle())()($seed), + (new Limit())()($size)(0) ); // Point free style. diff --git a/src/Operation/Reduce.php b/src/Operation/Reduce.php index f93364f9c..30d4a69e5 100644 --- a/src/Operation/Reduce.php +++ b/src/Operation/Reduce.php @@ -47,9 +47,9 @@ public function __invoke(): Closure */ static function ($initial) use ($callback): Closure { /** @var Closure(Iterator): Generator $pipe */ - $pipe = Pipe::of()( + $pipe = (new Pipe())()( (new Reduction())()($callback)($initial), - Last::of(), + (new Last())(), ); // Point free style. diff --git a/src/Operation/Scale.php b/src/Operation/Scale.php index 6d3928cf6..e6c1189bb 100644 --- a/src/Operation/Scale.php +++ b/src/Operation/Scale.php @@ -56,7 +56,7 @@ static function (float $base = 0.0) use ($lowerBound, $upperBound, $wantedLowerB $wantedLowerBound = (0.0 === $wantedLowerBound) ? (0.0 === $base ? 0.0 : 1.0) : $wantedLowerBound; $wantedUpperBound = (1.0 === $wantedUpperBound) ? (0.0 === $base ? 1.0 : $base) : $wantedUpperBound; /** @var callable(Generator):Generator $mapper */ - $mapper = Map::of()( + $mapper = (new Map())()( /** * @param float|int $v */ diff --git a/src/Operation/ScanLeft.php b/src/Operation/ScanLeft.php index 0e4bce0ca..3191561c6 100644 --- a/src/Operation/ScanLeft.php +++ b/src/Operation/ScanLeft.php @@ -29,7 +29,7 @@ final class ScanLeft extends AbstractOperation * @template V * @template W * - * @return Closure(callable((V|W)=, T=, TKey=, Iterator=): W): Closure(V): Closure(Iterator): Generator + * @return Closure(callable(mixed=, T=, TKey=, Iterator=): mixed): Closure(mixed): Closure(Iterator): Generator */ public function __invoke(): Closure { @@ -47,9 +47,9 @@ public function __invoke(): Closure */ static function ($initial) use ($callback): Closure { /** @var Closure(Iterator): Generator $pipe */ - $pipe = Pipe::of()( - Reduction::of()($callback)($initial), - Prepend::of()($initial) + $pipe = (new Pipe())()( + (new Reduction())()($callback)($initial), + (new Prepend())()($initial) ); return $pipe; diff --git a/src/Operation/ScanLeft1.php b/src/Operation/ScanLeft1.php index fe4614d76..7dbbf9d34 100644 --- a/src/Operation/ScanLeft1.php +++ b/src/Operation/ScanLeft1.php @@ -28,7 +28,7 @@ final class ScanLeft1 extends AbstractOperation * * @template V * - * @return Closure(callable(T|V, T, TKey, Iterator): V): Closure(Iterator): Generator + * @return Closure(callable(mixed, T, TKey, Iterator): mixed): Closure(Iterator): Generator */ public function __invoke(): Closure { @@ -48,10 +48,10 @@ static function (Iterator $iterator) use ($callback): Iterator { $initial = $iterator->current(); /** @var Closure(Iterator): Generator $pipe */ - $pipe = Pipe::of()( - Tail::of(), - Reduction::of()($callback)($initial), - Prepend::of()($initial) + $pipe = (new Pipe())()( + (new Tail())(), + (new Reduction())()($callback)($initial), + (new Prepend())()($initial) ); return $pipe($iterator); diff --git a/src/Operation/ScanRight.php b/src/Operation/ScanRight.php index f08eeeafd..13c9166e5 100644 --- a/src/Operation/ScanRight.php +++ b/src/Operation/ScanRight.php @@ -29,7 +29,7 @@ final class ScanRight extends AbstractOperation * @template V * @template W * - * @return Closure(callable((V|W)=, T=, TKey=, Iterator=): W): Closure(V): Closure(Iterator): Generator + * @return Closure(callable(mixed=, T=, TKey=, Iterator=): mixed): Closure(mixed): Closure(Iterator): Generator */ public function __invoke(): Closure { @@ -47,11 +47,11 @@ public function __invoke(): Closure */ static function ($initial) use ($callback): Closure { /** @var Closure(Iterator):(Generator) $pipe */ - $pipe = Pipe::of()( - Reverse::of(), - Reduction::of()($callback)($initial), - Reverse::of(), - Append::of()($initial) + $pipe = (new Pipe())()( + (new Reverse())(), + (new Reduction())()($callback)($initial), + (new Reverse())(), + (new Append())()($initial) ); // Point free style. diff --git a/src/Operation/ScanRight1.php b/src/Operation/ScanRight1.php index 704adeb2b..b7ca9bba5 100644 --- a/src/Operation/ScanRight1.php +++ b/src/Operation/ScanRight1.php @@ -28,7 +28,7 @@ final class ScanRight1 extends AbstractOperation * * @template V * - * @return Closure(callable(T|V, T, TKey, Iterator): V): Closure(Iterator): Generator + * @return Closure(callable(mixed, T, TKey, Iterator): mixed): Closure(Iterator): Generator */ public function __invoke(): Closure { @@ -40,10 +40,10 @@ public function __invoke(): Closure */ static function (callable $callback): Closure { /** @var Closure(Iterator): Generator $pipe */ - $pipe = Pipe::of()( - Reverse::of(), - ScanLeft1::of()($callback), - Reverse::of() + $pipe = (new Pipe())()( + (new Reverse())(), + (new ScanLeft1())()($callback), + (new Reverse())() ); // Point free style. diff --git a/src/Operation/Slice.php b/src/Operation/Slice.php index 32b48fb12..14bf2d66f 100644 --- a/src/Operation/Slice.php +++ b/src/Operation/Slice.php @@ -38,16 +38,16 @@ public function __invoke(): Closure */ static function (int $length = -1) use ($offset): Closure { /** @var Closure(Iterator): Generator $skip */ - $skip = Drop::of()($offset); + $skip = (new Drop())()($offset); if (-1 === $length) { return $skip; } /** @var Closure(Iterator): Generator $pipe */ - $pipe = Pipe::of()( + $pipe = (new Pipe())()( $skip, - Limit::of()($length)(0) + (new Limit())()($length)(0) ); // Point free style. diff --git a/src/Operation/Tails.php b/src/Operation/Tails.php index 6d94ed10f..be6f826ab 100644 --- a/src/Operation/Tails.php +++ b/src/Operation/Tails.php @@ -37,11 +37,11 @@ public function __invoke(): Closure */ static function (Iterator $iterator): Generator { /** @var Iterator $iterator */ - $iterator = Pack::of()($iterator); + $iterator = (new Pack())()($iterator); $data = [...$iterator]; while ([] !== $data) { - yield [...Unpack::of()(new ArrayIterator($data))]; + yield [...(new Unpack())()(new ArrayIterator($data))]; array_shift($data); } diff --git a/src/Operation/Unpack.php b/src/Operation/Unpack.php index 376c3bba2..2b74c729d 100644 --- a/src/Operation/Unpack.php +++ b/src/Operation/Unpack.php @@ -21,22 +21,19 @@ /** * @immutable * - * @template NewTKey - * @template NewT - * * @template TKey - * @template T of array{0: NewTKey, 1: NewT} + * @template T */ final class Unpack extends AbstractOperation { /** * @pure * - * @return Closure(Iterator): Generator + * @return Closure(Iterator): Generator */ public function __invoke(): Closure { - /** @var Closure(Iterator): Generator $pipe */ + /** @var Closure(Iterator): Generator $pipe */ $pipe = Pipe::of()( Map::of()(static fn (iterable $iterable): Iterator => (new IterableIteratorAggregate($iterable))->getIterator()), Map::of()(Chunk::of()(2)), diff --git a/src/Operation/Window.php b/src/Operation/Window.php index 335c3513b..f0ff9ace3 100644 --- a/src/Operation/Window.php +++ b/src/Operation/Window.php @@ -36,7 +36,7 @@ public function __invoke(): Closure */ static function (int $size): Closure { /** @var Closure(Iterator): Generator> $reduction */ - $reduction = Reduction::of()( + $reduction = (new Reduction())()( /** * @param list $stack * @param T $current diff --git a/tests/static-analysis/map.php b/tests/static-analysis/map.php index 988598cc8..ab51e8975 100644 --- a/tests/static-analysis/map.php +++ b/tests/static-analysis/map.php @@ -65,7 +65,15 @@ function map_checkMapClass(CollectionInterface $collection): void // VALID failures due to usage with wrong types -/** @psalm-suppress InvalidScalarArgument @phpstan-ignore-next-line */ +/** + * @psalm-suppress InvalidArgument + * @psalm-suppress InvalidScalarArgument + * @phpstan-ignore-next-line + */ map_checkListInt(Collection::fromIterable(['foo' => 'bar'])->map($square)); -/** @psalm-suppress InvalidScalarArgument @phpstan-ignore-next-line */ +/** + * @psalm-suppress InvalidArgument + * @psalm-suppress InvalidScalarArgument + * @phpstan-ignore-next-line + */ map_checkMapString(Collection::fromIterable([1, 2, 3])->map($appendBar));