Total Complexity | 7 |
Total Lines | 53 |
Duplicated Lines | 0 % |
Coverage | 95.83% |
Changes | 0 |
1 | <?php |
||
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 fromString(Str $string): Value |
|
39 | { |
||
40 | 3 | $string = $string->toEncoding('ASCII'); |
|
41 | |||
42 | 3 | return new self( |
|
43 | 3 | SignedLongInteger::fromString($string->substring(1))->original(), |
|
44 | 3 | UnsignedOctet::fromString($string->substring(0, 1))->original() |
|
45 | ); |
||
46 | } |
||
47 | |||
48 | 3 | public static function cut(Str $string): Str |
|
49 | { |
||
50 | return $string |
||
51 | 3 | ->toEncoding('ASCII') |
|
52 | 3 | ->substring(0, 1) |
|
53 | 3 | ->append( |
|
54 | 3 | (string) SignedLongInteger::cut($string->substring(1)) |
|
55 | ); |
||
56 | } |
||
57 | |||
58 | 5 | public function original(): Number |
|
59 | { |
||
60 | 5 | return $this->original; |
|
61 | } |
||
62 | |||
63 | 5 | public function __toString(): string |
|
66 | } |
||
67 | |||
68 | 6 | public static function definitionSet(): Set |
|
71 | } |
||
72 | } |
||
73 |