Completed
Push — master ( 785bde...8b4d11 )
by Freek
01:29
created

src/Macros/ParallelMap.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Spatie\CollectionMacros\Macros;
4
5
use Amp\Parallel\Worker\Pool;
6
use function Amp\Promise\wait;
7
use Illuminate\Support\Collection;
8
use Amp\Parallel\Worker\DefaultPool;
9
use function Amp\ParallelFunctions\parallelMap;
10
11
/*
12
 * Idential to map but each item will be processed in parallel.
13
 *
14
 * This function requires the installation of amphp/parallel-functions
15
 *
16
 * @param callable $callback
17
 *
18
 * @return \Illuminate\Support\Collection
19
 */
20
class ParallelMap
21
{
22
    public function __invoke()
23
    {
24
        return function (callable $callback, $workers = null): Collection {
25
            $pool = null;
26
27
            if ($workers instanceof Pool) {
28
                $pool = $workers;
29
            }
30
31
            if (is_int($workers)) {
32
                $pool = new DefaultPool($workers);
33
            }
34
35
            $promises = parallelMap($this->items, $callback, $pool);
36
37
            return new static(wait($promises));
0 ignored issues
show
The call to ParallelMap::__construct() has too many arguments starting with \Amp\Promise\wait($promises).

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
38
        };
39
    }
40
}
41