GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

SignalAware   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 95.83%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 48
ccs 23
cts 24
cp 0.9583
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A channel() 0 5 1
A close() 0 3 1
A __construct() 0 4 1
A register() 0 19 2
A closed() 0 3 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\AMQP\Client;
5
6
use Innmind\AMQP\Client as ClientInterface;
7
use Innmind\OperatingSystem\CurrentProcess\Signals;
8
use Innmind\Signals\Signal;
9
10
final class SignalAware implements ClientInterface
11
{
12
    private $client;
13
    private $signals;
14
    private $handlersRegistered = false;
15
16 4
    public function __construct(ClientInterface $client, Signals $signals)
17
    {
18 4
        $this->client = $client;
19 4
        $this->signals = $signals;
20 4
    }
21
22 2
    public function channel(): Channel
23
    {
24 2
        $this->register();
25
26 2
        return $this->client->channel();
27
    }
28
29 2
    public function closed(): bool
30
    {
31 2
        return $this->client->closed();
32
    }
33
34 2
    public function close(): void
35
    {
36 2
        $this->client->close();
37 2
    }
38
39 2
    private function register(): void
40
    {
41 2
        if ($this->handlersRegistered === true) {
42
            return;
43
        }
44
45
        $softClose = function(): void {
46 2
            $this->close();
47 2
        };
48
49
        $this->signals->listen(Signal::hangup(), static function() {
50
            //do nothing so it can run in background
51 2
        });
52 2
        $this->signals->listen(Signal::interrupt(), $softClose);
53 2
        $this->signals->listen(Signal::abort(), $softClose);
54 2
        $this->signals->listen(Signal::terminate(), $softClose);
55 2
        $this->signals->listen(Signal::terminalStop(), $softClose);
56 2
        $this->signals->listen(Signal::alarm(), $softClose);
57 2
        $this->handlersRegistered = true;
58 2
    }
59
}
60