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 ( 42629b...a0d7f6 )
by Baptiste
02:39
created

MessageReader::__invoke()   F

Complexity

Conditions 16
Paths 16384

Size

Total Lines 140
Code Lines 90

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 43
CRAP Score 16

Importance

Changes 0
Metric Value
dl 0
loc 140
ccs 43
cts 43
cp 1
rs 2
c 0
b 0
f 0
cc 16
eloc 90
nc 16384
nop 1
crap 16

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\AMQP\Transport\Connection;
5
6
use Innmind\AMQP\{
7
    Model\Basic\Message,
8
    Model\Basic\Message\Generic,
9
    Model\Basic\Message\ContentType,
10
    Model\Basic\Message\ContentEncoding,
11
    Model\Basic\Message\DeliveryMode,
12
    Model\Basic\Message\Priority,
13
    Model\Basic\Message\CorrelationId,
14
    Model\Basic\Message\ReplyTo,
15
    Model\Basic\Message\Id,
16
    Model\Basic\Message\Type,
17
    Model\Basic\Message\UserId,
18
    Model\Basic\Message\AppId,
19
    Transport\Connection,
20
    Transport\Frame\Value
21
};
22
use Innmind\TimeContinuum\ElapsedPeriod;
23
use Innmind\Immutable\{
24
    Map,
25
    Str
26
};
27
28
final class MessageReader
29
{
30 13
    public function __invoke(Connection $connection): Message
31
    {
32 13
        $header = $connection->wait();
33
        $bodySize = $header
34 13
            ->values()
35 13
            ->first()
36 13
            ->original()
37 13
            ->value();
38
        $flagBits = $header
39 13
            ->values()
40 13
            ->get(1)
41 13
            ->original()
42 13
            ->value();
43 13
        $payload = new Str('');
44
45 13
        while ($payload->length() !== $bodySize) {
46 13
            $payload = $payload->append(
47
                (string) $connection
48 13
                    ->wait()
49 13
                    ->values()
50 13
                    ->first()
51 13
                    ->original()
52
            );
53
        }
54
55 13
        $message = new Generic($payload);
56
        $properties = $header
57 13
            ->values()
58 13
            ->drop(2);
59
60 13
        if ($flagBits & (1 << 15)) {
61 1
            [$topLevel, $subType] = explode(
62 1
                '/',
63 1
                (string) $properties->first()->original()
64
            );
65 1
            $message = $message->withContentType(new ContentType(
66 1
                $topLevel,
67 1
                $subType
68
            ));
69 1
            $properties = $properties->drop(1);
70
        }
71
72 13
        if ($flagBits & (1 << 14)) {
73 1
            $message = $message->withContentEncoding(new ContentEncoding(
74 1
                (string) $properties->first()->original()
75
            ));
76 1
            $properties = $properties->drop(1);
77
        }
78
79 13
        if ($flagBits & (1 << 13)) {
80 1
            $message = $message->withHeaders(
81
                $properties
82 1
                    ->first()
83 1
                    ->original()
84 1
                    ->reduce(
85 1
                        new Map('string', 'mixed'),
86 1
                        static function(Map $carry, string $key, Value $value): Map {
87 1
                            return $carry->put(
88 1
                                $key,
89 1
                                $value->original()
90
                            );
91 1
                        }
92
                    )
93
            );
94
            $properties = $properties->drop(1);
95
        }
96
97
        if ($flagBits & (1 << 12)) {
98
            $message = $message->withDeliveryMode(
99
                $properties->first()->original()->value() === DeliveryMode::persistent()->toInt() ?
100
                    DeliveryMode::persistent() : DeliveryMode::nonPersistent()
101
            );
102
            $properties = $properties->drop(1);
103
        }
104
105
        if ($flagBits & (1 << 11)) {
106
            $message = $message->withPriority(new Priority(
107
                $properties->first()->original()->value()
108
            ));
109
            $properties = $properties->drop(1);
110
        }
111
112
        if ($flagBits & (1 << 10)) {
113
            $message = $message->withCorrelationId(new CorrelationId(
114
                (string) $properties->first()->original()
115
            ));
116
            $properties = $properties->drop(1);
117
        }
118
119
        if ($flagBits & (1 << 9)) {
120
            $message = $message->withReplyTo(new ReplyTo(
121
                (string) $properties->first()->original()
122
            ));
123
            $properties = $properties->drop(1);
124
        }
125
126
        if ($flagBits & (1 << 8)) {
127
            $message = $message->withExpiration(new ElapsedPeriod(
128
                (int) (string) $properties->first()->original()
129
            ));
130
            $properties = $properties->drop(1);
131
        }
132
133
        if ($flagBits & (1 << 7)) {
134
            $message = $message->withId(new Id(
135
                (string) $properties->first()->original()
136
            ));
137
            $properties = $properties->drop(1);
138
        }
139
140
        if ($flagBits & (1 << 6)) {
141
            $message = $message->withTimestamp(
142
                $properties->first()->original()
143
            );
144
            $properties = $properties->drop(1);
145
        }
146
147
        if ($flagBits & (1 << 5)) {
148
            $message = $message->withType(new Type(
149
                (string) $properties->first()->original()
150
            ));
151
            $properties = $properties->drop(1);
152
        }
153
154
        if ($flagBits & (1 << 4)) {
155
            $message = $message->withUserId(new UserId(
156
                (string) $properties->first()->original()
157
            ));
158
            $properties = $properties->drop(1);
159
        }
160
161
        if ($flagBits & (1 << 3)) {
162
            $message = $message->withAppId(new AppId(
163
                (string) $properties->first()->original()
164
            ));
165
            $properties = $properties->drop(1);
0 ignored issues
show
Unused Code introduced by
$properties is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
166
        }
167
168
        return $message;
169
    }
170
}
171