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.

Decimal::of()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1.0156

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 6
ccs 3
cts 4
cp 0.75
crap 1.0156
rs 10
c 0
b 0
f 0
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 12
    public function __construct(Integer $value, Integer $scale)
26
    {
27 12
        $this->scale = $scale;
28 12
        $this->value = $value;
29 12
        $this->original = $value->divideBy(
30 12
            (new Integer(10))->power($scale)
31
        );
32 12
    }
33
34 8
    public static function of(Integer $value, Integer $scale): self
35
    {
36 8
        SignedLongInteger::of($value);
37 4
        UnsignedOctet::of($scale);
38
39
        return new self($value, $scale);
40
    }
41
42 6
    public static function fromStream(Readable $stream): Value
43
    {
44 6
        $scale = UnsignedOctet::fromStream($stream)->original();
45 6
        $value = SignedLongInteger::fromStream($stream)->original();
46
47 6
        return new self($value, $scale);
48
    }
49
50 10
    public function original(): Number
51
    {
52 10
        return $this->original;
53
    }
54
55 10
    public function __toString(): string
56
    {
57 10
        return $this->string ?? $this->string = new UnsignedOctet($this->scale).new SignedLongInteger($this->value);
58
    }
59
60
    public static function definitionSet(): Set
61
    {
62
        return self::$definitionSet ?? self::$definitionSet = new NaturalNumbers;
63
    }
64
}
65