Passed
Pull Request — master (#6)
by PHPinnacle
03:55 queued 01:47
created

ParallelProcessor::__construct()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of PHPinnacle/Ensign.
4
 *
5
 * (c) PHPinnacle Team <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types = 1);
12
13
namespace PHPinnacle\Ensign\Processor;
14
15
use Amp\Parallel\Worker\DefaultPool;
16
use Amp\Parallel\Worker\Pool;
17
use Amp\ParallelFunctions;
18
use Amp\Promise;
19
use PHPinnacle\Ensign\Processor;
20
use PHPinnacle\Ensign\Token;
21
22
final class ParallelProcessor extends Processor
23
{
24
    /**
25
     * @var Pool
26
     */
27
    private $pool;
28
29
    /**
30
     * @param Pool $pool
31
     */
32
    public function __construct(Pool $pool = null)
33
    {
34
        $this->pool = $pool ?: new DefaultPool();
35
    }
36
37
    /**
38
     * @return Promise
39
     */
40
    public function shutdown(): Promise
41
    {
42
        return $this->pool->shutdown();
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    protected function process(callable $handler, array $arguments, Token $token): callable
49
    {
50
        return function () use ($handler, $arguments, $token) {
0 ignored issues
show
Unused Code introduced by
The import $token is not used and could be removed.

This check looks for imports that have been defined, but are not used in the scope.

Loading history...
51
            $parallel = ParallelFunctions\parallel($handler, $this->pool);
0 ignored issues
show
Bug introduced by
The function parallel was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
            $parallel = /** @scrutinizer ignore-call */ ParallelFunctions\parallel($handler, $this->pool);
Loading history...
52
53
            return $parallel(...$arguments);
54
        };
55
    }
56
}
57