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 ( e71353...ee213a )
by Baptiste
01:44
created

Protocol::read()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\AMQP\Transport\Protocol\v091;
5
6
use Innmind\AMQP\{
7
    Transport\Protocol as ProtocolInterface,
8
    Transport\Protocol\Version,
9
    Transport\Protocol\Connection as ConnectionInterface,
10
    Transport\Protocol\Channel as ChannelInterface,
11
    Transport\Protocol\Exchange as ExchangeInterface,
12
    Transport\Protocol\Queue as QueueInterface,
13
    Transport\Protocol\Basic as BasicInterface,
14
    Transport\Protocol\Transaction as TransactionInterface,
15
    Transport\Protocol\ArgumentTranslator,
16
    Transport\Frame\Method,
17
    Transport\Frame\Visitor\ChunkArguments,
18
    Transport\Frame\Value\UnsignedOctet,
19
    Transport\Frame\Value\UnsignedShortInteger,
20
    Transport\Frame\Value\UnsignedLongLongInteger,
21
    Transport\Frame\Value\Timestamp,
22
    Transport\Frame\Value\Table,
23
    Transport\Frame\Value\ShortString,
24
    Exception\VersionNotUsable
25
};
26
use Innmind\Immutable\{
27
    Str,
28
    StreamInterface
29
};
30
31
final class Protocol implements ProtocolInterface
32
{
33
    private $version;
34
    private $read;
35 79
    private $connection;
36
    private $channel;
37 79
    private $exchange;
38 79
    private $queue;
39 79
    private $basic;
40 79
    private $transaction;
41 79
42 79
    public function __construct(ArgumentTranslator $translator)
43 79
    {
44 79
        $this->version = new Version(0, 9, 1);
45 79
        $this->read = new Reader;
46
        $this->connection = new Connection;
47 18
        $this->channel = new Channel;
48
        $this->exchange = new Exchange($translator);
49 18
        $this->queue = new Queue($translator);
50
        $this->basic = new Basic($translator);
51
        $this->transaction = new Transaction;
52 4
    }
53
54 4
    public function version(): Version
55 2
    {
56
        return $this->version;
57
    }
58 2
59
    public function use(Version $version): ProtocolInterface
60
    {
61
        if (!$version->compatibleWith($this->version)) {
62
            throw new VersionNotUsable($version);
63
        }
64 18
65
        return $this;
66 18
    }
67
68
    /**
69 70
     * {@inheritdoc}
70
     */
71 70
    public function read(Method $method, Str $arguments): StreamInterface
72
    {
73
        return ($this->read)($method, $arguments);
74 18
    }
75
76 18
    /**
77
     * {@inheritdoc}
78
     */
79 17
    public function readHeader(Str $payload): StreamInterface
80
    {
81 17
        $chunk = new ChunkArguments(
82
            UnsignedLongLongInteger::class,
83
            UnsignedShortInteger::class
84 3
        );
85
        [$bodySize, $flagBits] = $chunk($payload);
0 ignored issues
show
Bug introduced by
The variable $bodySize does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $flagBits seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
86 3
87
        $flagBits = $flagBits->original()->value();
0 ignored issues
show
Bug introduced by
The variable $flagBits seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
88
        $toChunk = [
89 6
            UnsignedLongLongInteger::class, //body size
90
            UnsignedShortInteger::class, // flag bits
91 6
        ];
92
93
        if ($flagBits & (1 << 15)) {
94 1
            $toChunk[] = ShortString::class; //content type
95
        }
96 1
97
        if ($flagBits & (1 << 14)) {
98
            $toChunk[] = ShortString::class; //content encoding
99 4
        }
100
101 4
        if ($flagBits & (1 << 13)) {
102
            $toChunk[] = Table::class; //headers
103
        }
104
105
        if ($flagBits & (1 << 12)) {
106
            $toChunk[] = UnsignedOctet::class; //delivery mode
107
        }
108
109
        if ($flagBits & (1 << 11)) {
110
            $toChunk[] = UnsignedOctet::class; //priority
111
        }
112
113
        if ($flagBits & (1 << 10)) {
114
            $toChunk[] = ShortString::class; //correlation id
115
        }
116
117
        if ($flagBits & (1 << 9)) {
118
            $toChunk[] = ShortString::class; //reply to
119
        }
120
121
        if ($flagBits & (1 << 8)) {
122
            $toChunk[] = ShortString::class; //expiration
123
        }
124
125
        if ($flagBits & (1 << 7)) {
126
            $toChunk[] = ShortString::class; //id
127
        }
128
129
        if ($flagBits & (1 << 6)) {
130
            $toChunk[] = Timestamp::class; //timestamp
131
        }
132
133
        if ($flagBits & (1 << 5)) {
134
            $toChunk[] = ShortString::class; //type
135
        }
136
137
        if ($flagBits & (1 << 4)) {
138
            $toChunk[] = ShortString::class; //user id
139
        }
140
141
        if ($flagBits & (1 << 3)) {
142
            $toChunk[] = ShortString::class; //app id
143
        }
144
145
        return (new ChunkArguments(...$toChunk))($payload);
146
    }
147
148
    public function method(string $name): Method
149
    {
150
        return Methods::get($name);
151
    }
152
153
    public function connection(): ConnectionInterface
154
    {
155
        return $this->connection;
156
    }
157
158
    public function channel(): ChannelInterface
159
    {
160
        return $this->channel;
161
    }
162
163
    public function exchange(): ExchangeInterface
164
    {
165
        return $this->exchange;
166
    }
167
168
    public function queue(): QueueInterface
169
    {
170
        return $this->queue;
171
    }
172
173
    public function basic(): BasicInterface
174
    {
175
        return $this->basic;
176
    }
177
178
    public function transaction(): TransactionInterface
179
    {
180
        return $this->transaction;
181
    }
182
}
183