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
Pull Request — develop (#1)
by Baptiste
01:41
created

UnsignedOctet   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 38
ccs 15
cts 16
cp 0.9375
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 3 1
A fromStream() 0 5 1
A original() 0 3 1
A definitionSet() 0 5 1
A __construct() 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 unsigned shortshort
19
 */
20
final class UnsignedOctet implements Value
21
{
22
    private static $definitionSet;
23
24
    private $value;
25
    private $original;
26
27 141
    public function __construct(Integer $octet)
28
    {
29 141
        if (!self::definitionSet()->contains($octet)) {
30 3
            throw new OutOfRangeValue($octet, self::definitionSet());
31
        }
32
33 138
        $this->original = $octet;
34 138
    }
35
36 82
    public static function fromStream(Readable $stream): Value
37
    {
38 82
        [, $octet] = unpack('C', (string) $stream->read(1));
39
40 82
        return new self(new Integer($octet));
41
    }
42
43 84
    public function original(): Integer
44
    {
45 84
        return $this->original;
46
    }
47
48 137
    public function __toString(): string
49
    {
50 137
        return $this->value ?? $this->value = chr($this->original->value());
51
    }
52
53 141
    public static function definitionSet(): Set
54
    {
55 141
        return self::$definitionSet ?? self::$definitionSet = Range::inclusive(
56
            new Integer(0),
57 141
            new Integer(255)
58
        );
59
    }
60
}
61