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 ( 081f57...404db9 )
by Baptiste
12s queued 11s
created

FrameReader   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Test Coverage

Coverage 97.73%

Importance

Changes 0
Metric Value
eloc 50
dl 0
loc 76
ccs 43
cts 44
cp 0.9773
rs 10
c 0
b 0
f 0
wmc 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 74 10
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
use Innmind\Filesystem\Stream\StringStream;
23
24
final class FrameReader
25
{
26 52
    public function __invoke(Readable $stream, Protocol $protocol): Frame
27
    {
28 52
        $octet = UnsignedOctet::fromStream($stream);
29
30
        try {
31 52
            $type = Type::fromInt($octet->original()->value());
32 2
        } catch (UnknownFrameType $e) {
33 2
            throw new NoFrameDetected(new StringStream(
34 2
                (string) $stream->read()->prepend((string) $octet)
35
            ));
36
        }
37
38 51
        $channel = new Channel(
39 51
            UnsignedShortInteger::fromStream($stream)->original()->value()
40
        );
41
        $payload = $stream
42 51
            ->read(UnsignedLongInteger::fromStream($stream)->original()->value())
43 51
            ->toEncoding('ASCII');
44
45
        if (
46
            (
47 51
                $type === Type::method() ||
48 51
                $type === Type::header()
49
            ) &&
50 51
            $payload->length() < 4
51
        ) {
52 1
            throw new PayloadTooShort;
53
        }
54
55 50
        $end = UnsignedOctet::fromStream($stream)->original()->value();
56
57 50
        if ($end !== Frame::end()) {
58 1
            throw new ReceivedFrameNotDelimitedCorrectly;
59
        }
60
61 49
        $payload = new StringStream((string) $payload);
62
63
        switch ($type) {
64 49
            case Type::method():
65 46
                $method = new Method(
66 46
                    UnsignedShortInteger::fromStream($payload)
67 46
                        ->original()
68 46
                        ->value(),
69 46
                    UnsignedShortInteger::fromStream($payload)
70 46
                        ->original()
71 46
                        ->value()
72
                );
73
74 46
                return Frame::method(
75 46
                    $channel,
76 46
                    $method,
77 46
                    ...$protocol->read($method, $payload)
78
                );
79
80 19
            case Type::header():
81 17
                $class = UnsignedShortInteger::fromStream($payload)
82 17
                    ->original()
83 17
                    ->value();
84 17
                $payload->read(2); // walk over the weight definition
85
86 17
                return Frame::header(
87 17
                    $channel,
88 17
                    $class,
0 ignored issues
show
Bug introduced by
It seems like $class can also be of type double; however, parameter $class of Innmind\AMQP\Transport\Frame::header() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

88
                    /** @scrutinizer ignore-type */ $class,
Loading history...
89 17
                    ...$protocol->readHeader($payload)
90
                );
91
92 18
            case Type::body():
93 17
                return Frame::body($channel, $payload->read());
94
95 1
            case Type::heartbeat():
96 1
                return Frame::heartbeat();
97
98
            default:
99
                throw new LogicException; //if reached then there's an implementation error
100
        }
101
    }
102
}
103