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

Task::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 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