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   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 94.44%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 43
ccs 17
cts 18
cp 0.9444
rs 10
c 0
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A original() 0 3 1
A of() 0 7 2
A __construct() 0 3 1
A definitionSet() 0 5 1
A fromStream() 0 5 1
A __toString() 0 3 1
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