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

UnsignedLongLongInteger   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 91.3%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 8
dl 0
loc 53
ccs 21
cts 23
cp 0.913
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A fromString() 0 12 2
A cut() 0 4 1
A original() 0 4 1
A __toString() 0 4 1
A definitionSet() 0 7 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
    Exception\StringNotOfExpectedLength
10
};
11
use Innmind\Math\{
12
    Algebra\Integer,
13
    Algebra\Number\Infinite,
14
    DefinitionSet\Set,
15
    DefinitionSet\Range,
16
    DefinitionSet\Integers
17
};
18
use Innmind\Immutable\Str;
19
20
final class UnsignedLongLongInteger implements Value
21
{
22
    private static $definitionSet;
23
24
    private $value;
25
    private $original;
26
27 15
    public function __construct(Integer $value)
28
    {
29 15
        if (!self::definitionSet()->contains($value)) {
30 1
            throw new OutOfRangeValue($value, self::definitionSet());
31
        }
32
33 14
        $this->value = pack('J', $value->value());
34 14
        $this->original = $value;
35 14
    }
36
37 7
    public static function fromString(Str $string): Value
38
    {
39 7
        $string = $string->toEncoding('ASCII');
40
41 7
        if ($string->length() !== 8) {
42 1
            throw new StringNotOfExpectedLength($string, 8);
43
        }
44
45 6
        [, $value] = unpack('J', (string) $string);
1 ignored issue
show
Bug introduced by
The variable $value 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...
46
47 6
        return new self(new Integer($value));
48
    }
49
50 6
    public static function cut(Str $string): Str
51
    {
52 6
        return $string->toEncoding('ASCII')->substring(0, 8);
53
    }
54
55 11
    public function original(): Integer
56
    {
57 11
        return $this->original;
58
    }
59
60 13
    public function __toString(): string
61
    {
62 13
        return $this->value;
63
    }
64
65 15
    public static function definitionSet(): Set
66
    {
67 15
        return self::$definitionSet ?? self::$definitionSet = Range::inclusive(
68
            new Integer(0),
69
            Infinite::positive()
70 15
        )->intersect(new Integers);
71
    }
72
}
73