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

Decimal   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 95.83%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 8
dl 0
loc 55
ccs 23
cts 24
cp 0.9583
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 2
A fromString() 0 9 1
A cut() 0 9 1
A original() 0 4 1
A __toString() 0 4 1
A definitionSet() 0 4 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\Immutable\Str;
17
18
final class Decimal implements Value
19
{
20
    private static $definitionSet;
21
22
    private $value;
23
    private $original;
24
25 5
    public function __construct(Integer $value, Integer $scale)
26
    {
27 5
        if (!self::definitionSet()->contains($scale)) {
28
            throw new OutOfRangeValue($scale, self::definitionSet());
29
        }
30
31 5
        $this->value = (string) new UnsignedOctet($scale);
32 5
        $this->value .= (string) new SignedLongInteger($value);
33 5
        $this->original = $value->divideBy(
34 5
            (new Integer(10))->power($scale)
35
        );
36 5
    }
37
38 2
    public static function fromString(Str $string): Value
39
    {
40 2
        $string = $string->toEncoding('ASCII');
41
42 2
        return new self(
43 2
            SignedLongInteger::fromString($string->substring(1))->original(),
44 2
            UnsignedOctet::fromString($string->substring(0, 1))->original()
45
        );
46
    }
47
48 2
    public static function cut(Str $string): Str
49
    {
50
        return $string
51 2
            ->toEncoding('ASCII')
52 2
            ->substring(0, 1)
53 2
            ->append(
54 2
                (string) SignedLongInteger::cut($string->substring(1))
55
            );
56
    }
57
58 4
    public function original(): Number
59
    {
60 4
        return $this->original;
61
    }
62
63 4
    public function __toString(): string
64
    {
65 4
        return $this->value;
66
    }
67
68 5
    public static function definitionSet(): Set
69
    {
70 5
        return self::$definitionSet ?? self::$definitionSet = new NaturalNumbers;
71
    }
72
}
73