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.
Completed
Push — develop ( afd948...1cf017 )
by Baptiste
02:23
created

Lazy   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 94.29%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 2
dl 0
loc 87
ccs 33
cts 35
cp 0.9429
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A protocol() 0 4 1
A send() 0 4 1
A wait() 0 4 1
A maxFrameSize() 0 4 1
A close() 0 12 3
A closed() 0 4 2
A initialized() 0 4 1
A connection() 0 14 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\AMQP\Transport\Connection;
5
6
use Innmind\AMQP\{
7
    Model\Connection\MaxFrameSize,
8
    Transport\Connection as ConnectionInterface,
9
    Transport\Protocol,
10
    Transport\Frame,
11
    Exception\ConnectionClosed
12
};
13
use Innmind\Socket\Internet\Transport;
14
use Innmind\Url\UrlInterface;
15
use Innmind\TimeContinuum\{
16
    TimeContinuumInterface,
17
    ElapsedPeriod
18
};
19
20
final class Lazy implements ConnectionInterface
21
{
22
    private $transport;
23
    private $server;
24
    private $protocol;
25
    private $timeout;
26
    private $clock;
27
    private $connection;
28
    private $closed = false;
29
30 16
    public function __construct(
31
        Transport $transport,
32
        UrlInterface $server,
33
        Protocol $protocol,
34
        ElapsedPeriod $timeout,
35
        TimeContinuumInterface $clock
36
    ) {
37 16
        $this->transport = $transport;
38 16
        $this->server = $server;
39 16
        $this->protocol = $protocol;
40 16
        $this->timeout = $timeout;
41 16
        $this->clock = $clock;
42 16
    }
43
44 2
    public function protocol(): Protocol
45
    {
46 2
        return $this->connection()->protocol();
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 4
    public function send(Frame $frame): ConnectionInterface
53
    {
54 4
        return $this->connection()->send($frame);
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60 2
    public function wait(string ...$names): Frame
61
    {
62 2
        return $this->connection()->wait(...$names);
63
    }
64
65 2
    public function maxFrameSize(): MaxFrameSize
66
    {
67 2
        return $this->connection()->maxFrameSize();
68
    }
69 4
    public function close(): void
70
    {
71 4
        if ($this->closed) {
72
            return;
73
        }
74
75 4
        if ($this->initialized()) {
76
            $this->connection()->close();
77
        }
78
79 4
        $this->closed = true;
80 4
    }
81
82 4
    public function closed(): bool
83
    {
84 4
        return $this->closed || $this->connection()->closed();
85
    }
86
87 4
    private function initialized(): bool
88
    {
89 4
        return $this->connection instanceof Connection;
90
    }
91
92 12
    private function connection(): Connection
93
    {
94 12
        if ($this->closed) {
95 2
            throw new ConnectionClosed;
96
        }
97
98 10
        return $this->connection ?? $this->connection = new Connection(
99 10
            $this->transport,
100 10
            $this->server,
101 10
            $this->protocol,
102 10
            $this->timeout,
103 10
            $this->clock
104
        );
105
    }
106
}
107