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::fromString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
crap 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