diff --git a/src/Operation/AsyncMap.php b/src/Operation/AsyncMap.php index 35ba9c0f5..78e692611 100644 --- a/src/Operation/AsyncMap.php +++ b/src/Operation/AsyncMap.php @@ -14,6 +14,7 @@ use function Amp\ParallelFunctions\parallel; use function Amp\Promise\wait; use function Amp\Sync\ConcurrentIterator\map; +use function call_user_func_array; use function function_exists; // phpcs:disable @@ -65,7 +66,7 @@ static function (Iterator $iterator) use ($callbacks): Generator { * * @psalm-return T */ - static fn ($carry, callable $callback) => $callback($carry, $key); + static fn ($carry, callable $callback) => call_user_func_array($callback, [$carry, $key]); $callback = /** diff --git a/src/Operation/DropWhile.php b/src/Operation/DropWhile.php index d0a921a4b..4d3dee722 100644 --- a/src/Operation/DropWhile.php +++ b/src/Operation/DropWhile.php @@ -8,6 +8,8 @@ use Generator; use Iterator; +use function call_user_func_array; + /** * @psalm-template TKey * @psalm-template TKey of array-key @@ -60,7 +62,7 @@ static function (Iterator $iterator) use ($callbacks): Generator { * @psalm-param bool $carry * @psalm-param callable(T, TKey, Iterator): bool $callable */ - static fn (bool $carry, callable $callable): bool => $carry || $callable($current, $key, $iterator); + static fn (bool $carry, callable $callable): bool => $carry || call_user_func_array($callable, [$current, $key, $iterator]); $result = true; diff --git a/src/Operation/Every.php b/src/Operation/Every.php index 9dbcbf7ea..3705c6808 100644 --- a/src/Operation/Every.php +++ b/src/Operation/Every.php @@ -8,6 +8,8 @@ use Generator; use Iterator; +use function call_user_func_array; + /** * @psalm-template TKey * @psalm-template TKey of array-key @@ -52,7 +54,7 @@ static function (callable ...$callbacks): Closure { * @psalm-param bool $carry * @psalm-param callable(T, TKey, Iterator): bool $callable */ - static fn (bool $carry, callable $callable): bool => $carry || $callable($current, $key, $iterator); + static fn (bool $carry, callable $callable): bool => $carry || call_user_func_array($callable, [$current, $key, $iterator]); return /** diff --git a/src/Operation/GroupBy.php b/src/Operation/GroupBy.php index 84951d654..70314cea8 100644 --- a/src/Operation/GroupBy.php +++ b/src/Operation/GroupBy.php @@ -8,6 +8,8 @@ use Generator; use Iterator; +use function call_user_func_array; + /** * @psalm-template TKey * @psalm-template TKey of array-key @@ -62,7 +64,7 @@ static function (?callable $callable = null): Closure { * @psalm-return non-empty-array> */ static function (array $collect, $value, $key) use ($callback): array { - if (null !== $groupKey = $callback($value, $key)) { + if (null !== $groupKey = call_user_func_array($callback, [$value, $key])) { $collect[$groupKey][] = $value; } else { $collect[$key] = $value; diff --git a/src/Operation/Has.php b/src/Operation/Has.php index 1b38e8458..e3bcdbbd1 100644 --- a/src/Operation/Has.php +++ b/src/Operation/Has.php @@ -9,6 +9,8 @@ use Generator; use Iterator; +use function call_user_func_array; + /** * @psalm-template TKey * @psalm-template TKey of array-key @@ -52,7 +54,7 @@ static function (Iterator $iterator) use ($callbacks): Generator { * * @psalm-param Iterator $iterator */ - static fn ($value, $key, Iterator $iterator): bool => $callback($value, $key, $iterator) === $value, + static fn ($value, $key, Iterator $iterator): bool => call_user_func_array($callback, [$value, $key, $iterator]) === $value, $callbacks ); diff --git a/src/Operation/Map.php b/src/Operation/Map.php index fb6c8c6d3..415ffc675 100644 --- a/src/Operation/Map.php +++ b/src/Operation/Map.php @@ -8,6 +8,8 @@ use Generator; use Iterator; +use function call_user_func_array; + /** * @psalm-template TKey * @psalm-template TKey of array-key @@ -48,7 +50,7 @@ static function (Iterator $iterator) use ($callbacks): Generator { * * @psalm-return T */ - static fn ($carry, callable $callback) => $callback($carry, $key, $iterator); + static fn ($carry, callable $callback) => call_user_func_array($callback, [$carry, $key, $iterator]); foreach ($iterator as $key => $value) { yield $key => array_reduce($callbacks, $callbackFactory($key), $value); diff --git a/src/Operation/MatchOne.php b/src/Operation/MatchOne.php index 520f37930..08ba2efd4 100644 --- a/src/Operation/MatchOne.php +++ b/src/Operation/MatchOne.php @@ -8,6 +8,8 @@ use Generator; use Iterator; +use function call_user_func_array; + /** * @psalm-template TKey * @psalm-template TKey of array-key @@ -54,7 +56,7 @@ static function (callable ...$callbacks) use ($matcher): Closure { */ static fn ($value, $key, Iterator $iterator): bool => array_reduce( $callbacks, - static fn (bool $carry, callable $callback): bool => $carry || $callback($value, $key, $iterator), + static fn (bool $carry, callable $callback): bool => $carry || call_user_func_array($callback, [$value, $key, $iterator]), false ); @@ -70,7 +72,7 @@ static function (callable ...$callbacks) use ($matcher): Closure { * * @psalm-param Iterator $iterator */ - static fn ($value, $key, Iterator $iterator): bool => $matcher($value, $key, $iterator) === $callback($value, $key, $iterator); + static fn ($value, $key, Iterator $iterator): bool => call_user_func_array($matcher, [$value, $key, $iterator]) === call_user_func_array($callback, [$value, $key, $iterator]); $dropWhileCallback = /** diff --git a/src/Operation/Partition.php b/src/Operation/Partition.php index b8b986421..4b349400a 100644 --- a/src/Operation/Partition.php +++ b/src/Operation/Partition.php @@ -8,6 +8,8 @@ use Generator; use Iterator; +use function call_user_func_array; + /** * @psalm-template TKey * @psalm-template TKey of array-key @@ -60,7 +62,7 @@ static function (Iterator $iterator) use ($callbacks): Generator { * @psalm-param bool $carry * @psalm-param callable(T, TKey, Iterator): bool $callable */ - static fn (bool $carry, callable $callable): bool => $carry || $callable($current, $key, $iterator); + static fn (bool $carry, callable $callable): bool => $carry || call_user_func_array($callable, [$current, $key, $iterator]); $true = $false = []; diff --git a/src/Operation/Reduction.php b/src/Operation/Reduction.php index bd9b8b670..cfad01946 100644 --- a/src/Operation/Reduction.php +++ b/src/Operation/Reduction.php @@ -8,6 +8,8 @@ use Generator; use Iterator; +use function call_user_func_array; + /** * @psalm-template TKey * @psalm-template TKey of array-key @@ -43,7 +45,7 @@ public function __invoke(): Closure */ static function (Iterator $iterator) use ($callback, $initial): Generator { foreach ($iterator as $key => $value) { - yield $key => ($initial = $callback($initial, $value, $key, $iterator)); + yield $key => ($initial = call_user_func_array($callback, [$initial, $value, $key, $iterator])); } }; } diff --git a/src/Operation/Since.php b/src/Operation/Since.php index 15a7714e5..c83bffa90 100644 --- a/src/Operation/Since.php +++ b/src/Operation/Since.php @@ -8,6 +8,8 @@ use Generator; use Iterator; +use function call_user_func_array; + /** * @psalm-template TKey * @psalm-template TKey of array-key @@ -60,7 +62,7 @@ static function (Iterator $iterator) use ($callbacks): Generator { * @psalm-param bool $carry * @psalm-param callable(T, TKey, Iterator): bool $callable */ - static fn (bool $carry, callable $callable): bool => $carry || $callable($current, $key, $iterator); + static fn (bool $carry, callable $callable): bool => $carry || call_user_func_array($callable, [$current, $key, $iterator]); $result = false; diff --git a/src/Operation/Sort.php b/src/Operation/Sort.php index 7d2df7ab6..fbfd4397f 100644 --- a/src/Operation/Sort.php +++ b/src/Operation/Sort.php @@ -11,6 +11,8 @@ use Iterator; use loophp\collection\Contract\Operation; +use function call_user_func_array; + /** * @psalm-template TKey * @psalm-template TKey of array-key @@ -76,7 +78,7 @@ static function (Iterator $iterator) use ($type, $callback): Iterator { * @psalm-param array{0:TKey|T, 1:T|TKey} $left * @psalm-param array{0:TKey|T, 1:T|TKey} $right */ - static fn (array $left, array $right): int => $callback($left[1], $right[1]); + static fn (array $left, array $right): int => call_user_func_array($callback, [$left[1], $right[1]]); /** @psalm-var callable(Iterator): Generator | callable(Iterator): Generator $before */ $before = Pipe::of()(...$operations['before']); diff --git a/src/Operation/Split.php b/src/Operation/Split.php index 0ddc306fe..7f761b511 100644 --- a/src/Operation/Split.php +++ b/src/Operation/Split.php @@ -9,6 +9,8 @@ use Iterator; use loophp\collection\Contract\Operation\Splitable; +use function call_user_func_array; + /** * @psalm-template TKey * @psalm-template TKey of array-key @@ -67,7 +69,7 @@ static function (Iterator $iterator) use ($type, $callbacks): Generator { * @psalm-param bool $carry * @psalm-param callable(T, TKey, Iterator): bool $callable */ - static fn (bool $carry, callable $callable): bool => $carry || $callable($current, $key, $iterator); + static fn (bool $carry, callable $callable): bool => $carry || call_user_func_array($callable, [$current, $key, $iterator]); foreach ($iterator as $key => $value) { $callbackReturn = array_reduce( diff --git a/src/Operation/TakeWhile.php b/src/Operation/TakeWhile.php index 1a39ee962..9e64b6e78 100644 --- a/src/Operation/TakeWhile.php +++ b/src/Operation/TakeWhile.php @@ -8,6 +8,8 @@ use Generator; use Iterator; +use function call_user_func_array; + /** * @psalm-template TKey * @psalm-template TKey of array-key @@ -60,7 +62,7 @@ static function (Iterator $iterator) use ($callbacks): Generator { * @psalm-param bool $carry * @psalm-param callable(T, TKey, Iterator): bool $callable */ - static fn (bool $carry, callable $callable): bool => $carry || $callable($current, $key, $iterator); + static fn (bool $carry, callable $callable): bool => $carry || call_user_func_array($callable, [$current, $key, $iterator]); foreach ($iterator as $key => $current) { $result = array_reduce( diff --git a/src/Operation/Times.php b/src/Operation/Times.php index 25e6e93e0..7dcb98882 100644 --- a/src/Operation/Times.php +++ b/src/Operation/Times.php @@ -9,6 +9,8 @@ use Generator; use Iterator; +use function call_user_func; + /** * @psalm-template TKey * @psalm-template TKey of array-key @@ -45,7 +47,7 @@ static function (?Iterator $iterator = null) use ($number, $callback): Generator $callback ??= static fn (int $value): int => $value; for ($current = 1; $current <= $number; ++$current) { - yield $callback($current); + yield call_user_func($callback, $current); } }; } diff --git a/src/Operation/Unfold.php b/src/Operation/Unfold.php index f76a4350c..096a83e31 100644 --- a/src/Operation/Unfold.php +++ b/src/Operation/Unfold.php @@ -7,6 +7,8 @@ use Closure; use Generator; +use function call_user_func_array; + /** * @psalm-template TKey * @psalm-template TKey of array-key @@ -41,7 +43,7 @@ public function __invoke(): Closure static function () use ($parameters, $callback): Generator { while (true) { /** @psalm-var T $parameters */ - $parameters = $callback(...array_values((array) $parameters)); + $parameters = call_user_func_array($callback, array_values((array) $parameters)); yield $parameters; } diff --git a/src/Operation/Until.php b/src/Operation/Until.php index 59517ad5f..79d4541d0 100644 --- a/src/Operation/Until.php +++ b/src/Operation/Until.php @@ -8,6 +8,8 @@ use Generator; use Iterator; +use function call_user_func_array; + /** * @psalm-template TKey * @psalm-template TKey of array-key @@ -60,7 +62,7 @@ static function (Iterator $iterator) use ($callbacks): Generator { * @psalm-param bool $carry * @psalm-param callable(T, TKey, Iterator): bool $callable */ - static fn (bool $carry, callable $callable): bool => $carry || $callable($current, $key, $iterator); + static fn (bool $carry, callable $callable): bool => $carry || call_user_func_array($callable, [$current, $key, $iterator]); foreach ($iterator as $key => $current) { yield $key => $current;