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

Decimal   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 94.44%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 41
ccs 17
cts 18
cp 0.9444
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A __toString() 0 3 1
A original() 0 3 1
A definitionSet() 0 3 1
A fromStream() 0 6 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
};
10
use Innmind\Math\{
11
    Algebra\Number,
12
    Algebra\Integer,
13
    DefinitionSet\Set,
14
    DefinitionSet\NaturalNumbers,
15
};
16
use Innmind\Stream\Readable;
17
18
final class Decimal implements Value
19
{
20
    private static $definitionSet;
21
22
    private $value;
23
    private $original;
24
25 6
    public function __construct(Integer $value, Integer $scale)
26
    {
27 6
        if (!self::definitionSet()->contains($scale)) {
28
            throw new OutOfRangeValue($scale, self::definitionSet());
29
        }
30
31 6
        $this->value = (string) new UnsignedOctet($scale);
32 6
        $this->value .= (string) new SignedLongInteger($value);
33 6
        $this->original = $value->divideBy(
34 6
            (new Integer(10))->power($scale)
35
        );
36 6
    }
37
38 3
    public static function fromStream(Readable $stream): Value
39
    {
40 3
        $scale = UnsignedOctet::fromStream($stream)->original();
41 3
        $value = SignedLongInteger::fromStream($stream)->original();
42
43 3
        return new self($value, $scale);
44
    }
45
46 5
    public function original(): Number
47
    {
48 5
        return $this->original;
49
    }
50
51 5
    public function __toString(): string
52
    {
53 5
        return $this->value;
54
    }
55
56 6
    public static function definitionSet(): Set
57
    {
58 6
        return self::$definitionSet ?? self::$definitionSet = new NaturalNumbers;
59
    }
60
}
61