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

AmpToken::cancel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
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\Amp;
14
15
use Amp\CancellationTokenSource;
16
17
final class AmpToken
18
{
19
    /**
20
     * @var CancellationTokenSource
21
     */
22
    private $source;
23
24
    /**
25
     * @var \Amp\CancellationToken
26
     */
27
    private $token;
28
29
    /**
30
     * TaskToken constructor.
31
     */
32 9
    public function __construct()
33
    {
34 9
        $this->source = new CancellationTokenSource();
35 9
        $this->token  = $this->source->getToken();
36 9
    }
37
38
    /**
39
     * @return void
40
     */
41 1
    public function cancel(): void
42
    {
43 1
        $this->source->cancel();
44 1
    }
45
46
    /**
47
     * @return void
48
     */
49 9
    public function guard(): void
50
    {
51 9
        $this->token->throwIfRequested();
52 8
    }
53
}
54