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

SignedOctet   A

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 __toString() 0 3 1
A __construct() 0 3 1
A definitionSet() 0 5 1
A original() 0 3 1
A fromStream() 0 5 1
A of() 0 7 2
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
/**
18
 * Same as shortshort
19
 */
20
final class SignedOctet implements Value
21
{
22
    private static $definitionSet;
23
24
    private $value;
25
    private $original;
26
27 20
    public function __construct(Integer $octet)
28
    {
29 20
        $this->original = $octet;
30 20
    }
31
32 4
    public static function of(Integer $value): self
33
    {
34 4
        if (!self::definitionSet()->contains($value)) {
35 4
            throw new OutOfRangeValue($value, self::definitionSet());
36
        }
37
38
        return new self($value);
39
    }
40
41 12
    public static function fromStream(Readable $stream): Value
42
    {
43 12
        [, $value] = \unpack('c', (string) $stream->read(1));
44
45 12
        return new self(new Integer($value));
46
    }
47
48 14
    public function original(): Integer
49
    {
50 14
        return $this->original;
51
    }
52
53 22
    public function __toString(): string
54
    {
55 22
        return $this->value ?? $this->value = \pack('c', $this->original->value());
56
    }
57
58 4
    public static function definitionSet(): Set
59
    {
60 4
        return self::$definitionSet ?? self::$definitionSet = Range::inclusive(
61 2
            new Integer(-128),
62 4
            new Integer(127)
63
        );
64
    }
65
}
66