Passed
Push — master ( ce6fb4...8f579a )
by PHPinnacle
05:42 queued 03:05
created

Task   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 37
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A cancel() 0 3 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\Promise;
16
17
class Task implements Promise
18
{
19
    /**
20
     * @var Promise
21
     */
22
    private $promise;
23
24
    /**
25
     * @var TaskToken
26
     */
27
    private $token;
28
29
    /**
30
     * @param Promise   $promise
31
     * @param TaskToken $token
32
     */
33 5
    public function __construct(Promise $promise, TaskToken $token)
34
    {
35 5
        $this->promise = $promise;
36 5
        $this->token   = $token;
37 5
    }
38
39
    /**
40
     * @return void
41
     */
42 1
    public function cancel(): void
43
    {
44 1
        $this->token->cancel();
45 1
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50 5
    public function onResolve(callable $onResolved)
51
    {
52 5
        $this->token->guard();
53 4
        $this->promise->onResolve($onResolved);
54 4
    }
55
}
56