Passed
Pull Request — master (#6)
by PHPinnacle
02:45
created

Processor::recoil()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 4
nop 2
dl 0
loc 16
ccs 8
cts 8
cp 1
crap 3
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;
14
15
use Amp\LazyPromise;
16
use PHPinnacle\Identity\UUID;
17
18
abstract class Processor implements Contract\Processor
19
{
20
    /**
21
     * @var callable[]
22
     */
23
    protected $interruptions = [];
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 5
    public function interrupt(string $interrupt, callable $handler): void
29
    {
30 5
        $this->interruptions[$interrupt] = $handler;
31 5
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 8
    public function execute(callable $handler, array $arguments): Action
37
    {
38 8
        $id = UUID::random();
39
40 8
        $token   = new Token($id);
41 8
        $promise = new LazyPromise($this->process($handler, $arguments, $token));
42
43 8
        return new Action($id, $promise, $token);
44
    }
45
46
    /**
47
     * @param callable $handler
48
     * @param array    $arguments
49
     * @param Token    $token
50
     *
51
     * @return callable
52
     */
53
    abstract protected function process(callable $handler, array $arguments, Token $token): callable;
54
}
55