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.
Passed
Push — master ( 778995...e0837d )
by Baptiste
03:36
created

UnsignedShortInteger::fromStream()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\AMQP\Transport\Frame\Value;
5
6
use Innmind\AMQP\{
7
    Transport\Frame\Value,
8
    Exception\OutOfRangeValue,
9
};
10
use Innmind\Math\{
11
    Algebra\Integer,
12
    DefinitionSet\Set,
13
    DefinitionSet\Range,
14
};
15
use Innmind\Stream\Readable;
16
17
final class UnsignedShortInteger implements Value
18
{
19
    private static $definitionSet;
20
21
    private $value;
22
    private $original;
23
24 226
    public function __construct(Integer $value)
25
    {
26 226
        $this->original = $value;
27 226
    }
28
29 102
    public static function of(Integer $value): self
30
    {
31 102
        if (!self::definitionSet()->contains($value)) {
32 4
            throw new OutOfRangeValue($value, self::definitionSet());
33
        }
34
35 98
        return new self($value);
36
    }
37
38 128
    public static function fromStream(Readable $stream): Value
39
    {
40 128
        [, $value] = \unpack('n', (string) $stream->read(2));
41
42 128
        return new self(new Integer($value));
43
    }
44
45 150
    public function original(): Integer
46
    {
47 150
        return $this->original;
48
    }
49
50 224
    public function __toString(): string
51
    {
52 224
        return $this->value ?? $this->value = \pack('n', $this->original->value());
53
    }
54
55 102
    public static function definitionSet(): Set
56
    {
57 102
        return self::$definitionSet ?? self::$definitionSet = Range::inclusive(
58 2
            new Integer(0),
59 102
            new Integer(65535)
60
        );
61
    }
62
}
63