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.

Basic::consume()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 2.0014

Importance

Changes 0
Metric Value
cc 2
eloc 14
nc 2
nop 1
dl 0
loc 21
ccs 13
cts 14
cp 0.9286
crap 2.0014
rs 9.7998
c 0
b 0
f 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\AMQP\Client\Channel\Basic;
5
6
use Innmind\AMQP\{
7
    Client\Channel\Basic as BasicInterface,
8
    Model\Basic\Ack,
9
    Model\Basic\Cancel,
10
    Model\Basic\Consume,
11
    Model\Basic\Get as GetCommand,
12
    Model\Basic\Publish,
13
    Model\Basic\Qos,
14
    Model\Basic\Recover,
15
    Model\Basic\Reject,
16
    Model\Basic\Message\Locked,
17
    Transport\Connection,
18
    Transport\Connection\MessageReader,
19
    Transport\Frame,
20
    Transport\Frame\Channel,
21
};
22
use Innmind\TimeContinuum\ElapsedPeriod;
23
24
final class Basic implements BasicInterface
25
{
26
    private $connection;
27
    private $channel;
28
    private $read;
29
30 52
    public function __construct(Connection $connection, Channel $channel)
31
    {
32 52
        $this->connection = $connection;
33 52
        $this->channel = $channel;
34 52
        $this->read = new MessageReader;
35 52
    }
36
37 2
    public function ack(Ack $command): BasicInterface
38
    {
39 2
        $this->connection->send(
40 2
            $this->connection->protocol()->basic()->ack(
41 2
                $this->channel,
42 1
                $command
43
            )
44
        );
45
46 2
        return $this;
47
    }
48
49 4
    public function cancel(Cancel $command): BasicInterface
50
    {
51 4
        $this->connection->send(
52 4
            $this->connection->protocol()->basic()->cancel(
53 4
                $this->channel,
54 2
                $command
55
            )
56
        );
57
58 4
        if ($command->shouldWait()) {
59 2
            $this->connection->wait('basic.cancel-ok');
60
        }
61
62 4
        return $this;
63
    }
64
65 14
    public function consume(Consume $command): Consumer
66
    {
67 14
        $this->connection->send(
68 14
            $this->connection->protocol()->basic()->consume(
69 14
                $this->channel,
70 7
                $command
71
            )
72
        );
73
74 14
        if ($command->shouldWait()) {
75 14
            $frame = $this->connection->wait('basic.consume-ok');
76 14
            $consumerTag = (string) $frame->values()->first()->original();
77
        } else {
78
            $consumerTag = $command->consumerTag();
79
        }
80
81 14
        return new Consumer\Consumer(
82 14
            $this->connection,
83 7
            $command,
84 14
            $this->channel,
85 7
            $consumerTag
86
        );
87
    }
88
89 24
    public function get(GetCommand $command): Get
90
    {
91
        $frame = $this
92 24
            ->connection
93 24
            ->send($this->connection->protocol()->basic()->get(
94 24
                $this->channel,
95 12
                $command
96
            ))
97 24
            ->wait('basic.get-ok', 'basic.get-empty');
98
99 24
        if ($frame->is($this->connection->protocol()->method('basic.get-empty'))) {
100 8
            return new Get\GetEmpty;
101
        }
102
103 20
        $message = ($this->read)($this->connection);
104
105 20
        return new Get\GetOk(
106 20
            $this->connection,
107 20
            $this->channel,
108 10
            $command,
109 20
            new Locked($message),
110 20
            $frame->values()->first()->original()->value(), //deliveryTag
111 20
            $frame->values()->get(1)->original()->first(), //redelivered
112 20
            (string) $frame->values()->get(2)->original(), //exchange
113 20
            (string) $frame->values()->get(3)->original(), //routingKey
114 20
            $frame->values()->get(4)->original()->value() //messageCount
115
        );
116
    }
117
118 34
    public function publish(Publish $command): BasicInterface
119
    {
120
        $this
121 34
            ->connection
122 34
            ->protocol()
123 34
            ->basic()
124 34
            ->publish(
125 34
                $this->channel,
126 17
                $command,
127 34
                $this->connection->maxFrameSize()
128
            )
129
            ->foreach(function(Frame $frame): void {
130 34
                $this->connection->send($frame);
131 34
            });
132
133 34
        return $this;
134
    }
135
136 2
    public function qos(Qos $command): BasicInterface
137
    {
138
        $this
139 2
            ->connection
140 2
            ->send($this->connection->protocol()->basic()->qos(
141 2
                $this->channel,
142 1
                $command
143
            ))
144 2
            ->wait('basic.qos-ok');
145
146 2
        return $this;
147
    }
148
149
    public function recover(Recover $command): BasicInterface
150
    {
151
        $this
152
            ->connection
153
            ->send($this->connection->protocol()->basic()->recover(
154
                $this->channel,
155
                $command
156
            ))
157
            ->wait('basic.recover-ok');
158
159
        return $this;
160
    }
161
162 4
    public function reject(Reject $command): BasicInterface
163
    {
164 4
        $this->connection->send(
165 4
            $this->connection->protocol()->basic()->reject(
166 4
                $this->channel,
167 2
                $command
168
            )
169
        );
170
171 4
        return $this;
172
    }
173
}
174