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

FrameReader   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 15

Test Coverage

Coverage 96.3%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 11
c 2
b 1
f 1
lcom 0
cbo 15
dl 0
loc 85
ccs 26
cts 27
cp 0.963
rs 9.1666

1 Method

Rating   Name   Duplication   Size   Complexity  
C __invoke() 0 82 11
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\AMQP\Transport\Connection;
5
6
use Innmind\AMQP\{
7
    Transport\Protocol,
8
    Transport\Frame,
9
    Transport\Frame\Method,
10
    Transport\Frame\Type,
11
    Transport\Frame\Channel,
12
    Transport\Frame\Value\UnsignedOctet,
13
    Transport\Frame\Value\UnsignedShortInteger,
14
    Transport\Frame\Value\UnsignedLongInteger,
15
    Exception\ReceivedFrameNotDelimitedCorrectly,
16
    Exception\PayloadTooShort,
17
    Exception\UnknownFrameType,
18
    Exception\NoFrameDetected,
19
    Exception\LogicException
20
};
21
use Innmind\Stream\Readable;
22
23
final class FrameReader
24 22
{
25
    public function __invoke(Readable $stream, Protocol $protocol): Frame
26 22
    {
27
        $octet = $stream->read(1);
28
29 22
        try {
30 22
            $type = Type::fromInt(
31
                UnsignedOctet::fromString($octet)->original()->value()
32 2
            );
33 2
        } catch (UnknownFrameType $e) {
34
            throw new NoFrameDetected($octet->append((string) $stream->read()));
35
        }
36 21
37 21
        $channel = new Channel(
38
            UnsignedShortInteger::fromString($stream->read(2))->original()->value()
39
        );
40 21
        $payload = $stream
41 21
            ->read(UnsignedLongInteger::fromString($stream->read(4))->original()->value())
42
            ->toEncoding('ASCII');
43 21
44 1
        if (
45
            (
46
                $type === Type::method() ||
47 20
                $type === Type::header()
48
            ) &&
49 20
            $payload->length() < 4
50 2
        ) {
51
            throw new PayloadTooShort;
52
        }
53 18
54
        $end = $stream->read(1)->toEncoding('ASCII');
55 18
56
        if ($end->length() !== 1) {
57
            throw new ReceivedFrameNotDelimitedCorrectly;
58
        }
59 18
60 18
        $end = UnsignedOctet::fromString($end)->original()->value();
61 18
62 18
        if ($end !== 0xCE) {
63
            throw new ReceivedFrameNotDelimitedCorrectly;
64 18
        }
65
66 18
        switch ($type) {
67 18
            case Type::method():
68 18
                $method = $payload->substring(0, 4);
69 18
                $method = new Method(
70
                    UnsignedShortInteger::fromString($method->substring(0, 2))
71
                        ->original()
72
                        ->value(),
73
                    UnsignedShortInteger::fromString($method->substring(2, 4))
74
                        ->original()
75
                        ->value()
76
                );
77
                $arguments = $payload->substring(4);
78
79
                return Frame::command(
80
                    $channel,
81
                    $method,
82
                    ...$protocol->read($method, $arguments)
83
                );
84
85
            case Type::header():
86
                $header = $payload->substring(0, 4); //3 and 4 are the weight
87
                $class = UnsignedShortInteger::fromString($header->substring(0, 2))
88
                    ->original()
89
                    ->value();
90
91
                return Frame::header(
92
                    $channel,
93
                    $class,
94
                    ...$protocol->readHeader($payload->substring(4))
95
                );
96
97
            case Type::body():
98
                return Frame::body($channel, $payload);
99
100
            case Type::heartbeat():
101
                return Frame::heartbeat();
102
103
            default:
104
                throw new LogicException; //if reached then there's an implementation error
105
        }
106
    }
107
}
108