Passed
Push — master ( d68e66...3a2ed0 )
by PHPinnacle
03:05
created

AmpTask   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 45
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

4 Methods

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