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 — master ( 555617...d35983 )
by Baptiste
02:18
created

Lazy   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 91.89%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 2
dl 0
loc 91
ccs 34
cts 37
cp 0.9189
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 8 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
        if ($this->initialized()) {
85
            return $this->connection()->closed();
86
        }
87
88 4
        return $this->closed;
89
    }
90
91 6
    private function initialized(): bool
92
    {
93 6
        return $this->connection instanceof Connection;
94
    }
95
96 10
    private function connection(): Connection
97
    {
98 10
        if ($this->closed) {
99 2
            throw new ConnectionClosed;
100
        }
101
102 8
        return $this->connection ?? $this->connection = new Connection(
103 8
            $this->transport,
104 8
            $this->server,
105 8
            $this->protocol,
106 8
            $this->timeout,
107 8
            $this->clock
108
        );
109
    }
110
}
111