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.

Client::channel()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 0
dl 0
loc 15
ccs 9
cts 9
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\AMQP\Client;
5
6
use Innmind\AMQP\{
7
    Client as ClientInterface,
8
    Transport\Connection,
9
    Transport\Frame\Channel as Number,
10
};
11
use Innmind\OperatingSystem\CurrentProcess;
12
use Innmind\Immutable\Map;
13
14
final class Client implements ClientInterface
15
{
16
    private $connection;
17
    private $process;
18
    private $channels;
19
    private $channel = 1;
20
21 8
    public function __construct(Connection $connection, CurrentProcess $process)
22
    {
23 8
        $this->connection = $connection;
24 8
        $this->process = $process;
25 8
        $this->channels = new Map('int', Channel::class);
26 8
    }
27
28 4
    public function channel(): Channel
29
    {
30 4
        $pid = $this->process->id()->toInt();
31
32 4
        if ($this->channels->contains($pid)) {
33 2
            return $this->channels->get($pid);
34
        }
35
36 4
        $channel = new Channel\Channel(
37 4
            $this->connection,
38 4
            new Number($this->channel++)
39
        );
40 4
        $this->channels = $this->channels->put($pid, $channel);
41
42 4
        return $channel;
43
    }
44
45 2
    public function closed(): bool
46
    {
47 2
        return $this->connection->closed();
48
    }
49
50 2
    public function close(): void
51
    {
52 2
        if ($this->closed()) {
53 2
            return;
54
        }
55
56
        $this->channels->foreach(static function(int $pid, Channel $channel): void {
57 2
            $channel->close();
58 2
        });
59 2
        $this->connection->close();
60 2
    }
61
}
62