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   B

Complexity

Total Complexity 16

Size/Duplication

Total Lines 143
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 18

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 16
lcom 0
cbo 18
dl 0
loc 143
ccs 43
cts 43
cp 1
rs 7.3333
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
F __invoke() 0 140 16
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