Test Failed
Push — master ( 1bc1f8...877ced )
by PHPinnacle
05:28 queued 03:03
created

Action   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 84.62%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 56
ccs 11
cts 13
cp 0.8462
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A cancel() 0 5 1
A id() 0 3 1
A __construct() 0 5 1
A onResolve() 0 4 1
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\Deferred;
16
use Amp\Loop;
17
use Amp\Promise;
18
use PHPinnacle\Identity\UUID;
19
20
final class Action implements Promise
21
{
22
    /**
23
     * @var UUID
24
     */
25
    private $id;
26
27
    /**
28
     * @var Promise
29
     */
30
    private $promise;
31
32
    /**
33
     * @var Token
34
     */
35
    private $token;
36
37
    /**
38
     * @param UUID    $id
39
     * @param Promise $promise
40
     * @param Token   $token
41
     */
42 10
    public function __construct(UUID $id, Promise $promise, Token $token)
43
    {
44 10
        $this->id      = $id;
45 10
        $this->promise = $promise;
46 10
        $this->token   = $token;
47 10
    }
48
49
    /**
50
     * @return UUID
51
     */
52
    public function id(): UUID
53
    {
54
        return $this->id;
55
    }
56
57
    /**
58
     * @param string $reason
59
     *
60
     * @return Action
61
     */
62 1
    public function cancel(string $reason = null): self
63
    {
64 1
        $this->token->cancel($reason);
65
66 1
        return $this;
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72 9
    public function onResolve(callable $onResolved)
73
    {
74 9
        $this->token->guard();
75 8
        $this->promise->onResolve($onResolved);
76 8
    }
77
}
78