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.
Completed
Push — develop ( c3bf76...dc595a )
by Baptiste
03:31
created

UnsignedOctet::fromString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 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
    Exception\StringNotOfExpectedLength
10
};
11
use Innmind\Math\{
12
    Algebra\Integer,
13
    DefinitionSet\Set,
14
    DefinitionSet\Range,
15
    DefinitionSet\Integers
16
};
17
use Innmind\Immutable\Str;
18
19
/**
20
 * Same as unsigned shortshort
21
 */
22
final class UnsignedOctet implements Value
23
{
24
    private static $definitionSet;
25
26
    private $value;
27
    private $original;
28
29 84
    public function __construct(Integer $octet)
30
    {
31 84
        if (!self::definitionSet()->contains($octet)) {
32 3
            throw new OutOfRangeValue($octet, self::definitionSet());
33
        }
34
35 81
        $this->value = chr($octet->value());
36 81
        $this->original = $octet;
37 81
    }
38
39 40
    public static function fromString(Str $string): Value
40
    {
41 40
        $string = $string->toEncoding('ASCII');
42
43 40
        if ($string->length() !== 1) {
44 1
            throw new StringNotOfExpectedLength($string, 1);
45
        }
46
47 39
        [, $octet] = unpack('C', (string) $string);
48
49 39
        return new self(new Integer($octet));
50
    }
51
52 9
    public static function cut(Str $string): Str
53
    {
54 9
        return $string->toEncoding('ASCII')->substring(0, 1);
55
    }
56
57 40
    public function original(): Integer
58
    {
59 40
        return $this->original;
60
    }
61
62 77
    public function __toString(): string
63
    {
64 77
        return $this->value;
65
    }
66
67 84
    public static function definitionSet(): Set
68
    {
69 84
        return self::$definitionSet ?? self::$definitionSet = Range::inclusive(
70
            new Integer(0),
71
            new Integer(255)
72 84
        )->intersect(new Integers);
73
    }
74
}
75