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.

SignedShortInteger::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
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
use Innmind\Immutable\Str;
17
18
final class SignedShortInteger implements Value
19
{
20
    private static $definitionSet;
21
22
    private $value;
23
    private $original;
24
25 18
    public function __construct(Integer $value)
26
    {
27 18
        $this->original = $value;
28 18
    }
29
30 4
    public static function of(Integer $value): self
31
    {
32 4
        if (!self::definitionSet()->contains($value)) {
33 4
            throw new OutOfRangeValue($value, self::definitionSet());
34
        }
35
36
        return new self($value);
37
    }
38
39 8
    public static function fromStream(Readable $stream): Value
40
    {
41 8
        [, $value] = \unpack('s', (string) $stream->read(2));
42
43 8
        return new self(new Integer($value));
44
    }
45
46 16
    public function original(): Integer
47
    {
48 16
        return $this->original;
49
    }
50
51 16
    public function __toString(): string
52
    {
53 16
        return $this->value ?? $this->value = \pack('s', $this->original->value());
54
    }
55
56 4
    public static function definitionSet(): Set
57
    {
58 4
        return self::$definitionSet ?? self::$definitionSet = Range::inclusive(
59 2
            new Integer(-32768),
60 4
            new Integer(32767)
61
        );
62
    }
63
}
64