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.

Frame::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 3
dl 0
loc 21
ccs 14
cts 14
cp 1
crap 1
rs 9.8333
c 0
b 0
f 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\AMQP\Transport;
5
6
use Innmind\AMQP\Transport\Frame\{
7
    Type,
8
    Channel,
9
    Method,
10
    Value,
11
    Value\UnsignedOctet,
12
    Value\UnsignedShortInteger,
13
    Value\UnsignedLongInteger,
14
    Value\Text,
15
};
16
use Innmind\Math\Algebra\Integer;
17
use Innmind\Immutable\{
18
    Sequence,
19
    StreamInterface,
20
    Stream,
21
    Str,
22
};
23
24
final class Frame
25
{
26
    private $type;
27
    private $channel;
28
    private $method;
29
    private $values;
30
    private $string;
31
32 192
    private function __construct(
33
        Type $type,
34
        Channel $channel,
35
        Value ...$values
36
    ) {
37 192
        $this->type = $type;
38 192
        $this->channel = $channel;
39 192
        $this->values = new Stream(Value::class);
40
41 192
        $values = new Sequence(...$values);
42 192
        $payload = $values->join('')->toEncoding('ASCII');
43
44 192
        $frame = new Sequence(
45 192
            new UnsignedOctet(new Integer($type->toInt())),
46 192
            new UnsignedShortInteger(new Integer($channel->toInt())),
47 192
            new UnsignedLongInteger(new Integer($payload->length())),
48 96
            $payload
49
        );
50 192
        $this->string = (string) $frame
51 192
            ->add(new UnsignedOctet(new Integer(self::end())))
52 192
            ->join('');
53 192
    }
54
55 172
    public static function method(
56
        Channel $channel,
57
        Method $method,
58
        Value ...$values
59
    ): self {
60 172
        $self = new self(
61 172
            Type::method(),
62 86
            $channel,
63 172
            new UnsignedShortInteger(new Integer($method->class())),
64 172
            new UnsignedShortInteger(new Integer($method->method())),
65 172
            ...$values
66
        );
67 172
        $self->method = $method;
68 172
        $self->values = Sequence::of(...$values)->reduce(
69 172
            $self->values,
70
            static function(Stream $stream, Value $value): Stream {
71 160
                return $stream->add($value);
72 172
            }
73
        );
74
75 172
        return $self;
76
    }
77
78 54
    public static function header(
79
        Channel $channel,
80
        int $class,
81
        Value ...$values
82
    ): self {
83 54
        $self = new self(
84 54
            Type::header(),
85 27
            $channel,
86 54
            new UnsignedShortInteger(new Integer($class)),
87 54
            new UnsignedShortInteger(new Integer(0)), //weight
88 54
            ...$values
89
        );
90 54
        $self->values = Sequence::of(...$values)->reduce(
91 54
            $self->values,
92
            static function(Stream $stream, Value $value): Stream {
93 54
                return $stream->add($value);
94 54
            }
95
        );
96
97 54
        return $self;
98
    }
99
100 48
    public static function body(Channel $channel, Str $payload): self
101
    {
102 48
        $self = new self(
103 48
            Type::body(),
104 24
            $channel,
105 48
            $value = new Text($payload)
106
        );
107 48
        $self->values = $self->values->add($value);
108
109 48
        return $self;
110
    }
111
112 29
    public static function heartbeat(): self
113
    {
114 29
        return new self(
115 29
            Type::heartbeat(),
116 29
            new Channel(0)
117
        );
118
    }
119
120 170
    public function type(): Type
121
    {
122 170
        return $this->type;
123
    }
124
125 168
    public function channel(): Channel
126
    {
127 168
        return $this->channel;
128
    }
129
130 156
    public function is(Method $method): bool
131
    {
132 156
        if ($this->type() !== Type::method()) {
133 6
            return false;
134
        }
135
136 150
        return $this->method->equals($method);
137
    }
138
139
    /**
140
     * @return StreamInterface<Value>
141
     */
142 174
    public function values(): StreamInterface
143
    {
144 174
        return $this->values;
145
    }
146
147 110
    public function __toString(): string
148
    {
149 110
        return $this->string;
150
    }
151
152 192
    public static function end(): int
153
    {
154 192
        return 0xCE;
155
    }
156
}
157