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 ( faae32...638f88 )
by Baptiste
03:29
created

UnsignedOctet::fromString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 5
cts 6
cp 0.8333
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
crap 2.0185
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
    DefinitionSet\Integers
15
};
16
use Innmind\Immutable\Str;
17
18
/**
19
 * Same as unsigned shortshort
20
 */
21
final class UnsignedOctet implements Value
22
{
23
    private static $definitionSet;
24
25
    private $value;
26
    private $original;
27
28 26
    public function __construct(Integer $octet)
29
    {
30 26
        if (!self::definitionSet()->contains($octet)) {
31 3
            throw new OutOfRangeValue($octet, self::definitionSet());
32
        }
33
34 23
        $this->value = chr($octet->value());
35 23
        $this->original = $octet;
36 23
    }
37
38 11
    public static function fromString(Str $string): Value
39
    {
40 11
        $string = $string->toEncoding('ASCII');
41
42 11
        if ($string->length() !== 1) {
43
            throw new StringNotOfExpectedLength($string, 1);
44
        }
45
46 11
        [, $octet] = unpack('C', (string) $string);
1 ignored issue
show
Bug introduced by
The variable $octet does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
47
48 11
        return new self(new Integer($octet));
49
    }
50
51 3
    public static function cut(Str $string): Str
52
    {
53 3
        return $string->toEncoding('ASCII')->substring(0, 1);
54
    }
55
56 14
    public function original(): Integer
57
    {
58 14
        return $this->original;
59
    }
60
61 20
    public function __toString(): string
62
    {
63 20
        return $this->value;
64
    }
65
66 26
    public static function definitionSet(): Set
67
    {
68 26
        return self::$definitionSet ?? self::$definitionSet = Range::inclusive(
69
            new Integer(0),
70
            new Integer(255)
71 26
        )->intersect(new Integers);
72
    }
73
}
74