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 ( 081f57...404db9 )
by Baptiste
12s queued 11s
created

Decimal   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 39
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

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