Total Complexity | 6 |
Total Lines | 47 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
7 | class Price |
||
8 | { |
||
9 | private const DECIMALS = 2; |
||
10 | |||
11 | /** |
||
12 | * @var Decimal |
||
13 | */ |
||
14 | private $withVat; |
||
15 | |||
16 | 40 | public function __construct(string $withVat) |
|
17 | { |
||
18 | 40 | $withHigherPrecision = Decimal::fromString($withVat, self::DECIMALS + 1); |
|
19 | 40 | $truncated = $withHigherPrecision->floor(self::DECIMALS); |
|
20 | 40 | $this->withVat = $truncated; |
|
21 | 40 | } |
|
22 | |||
23 | /** |
||
24 | * @param self[] $prices |
||
25 | * @return self |
||
26 | */ |
||
27 | 17 | public static function sum(array $prices): self |
|
32 | } |
||
33 | |||
34 | 13 | public function getWithVat(): string |
|
35 | { |
||
36 | 13 | return (string) $this->withVat->floor(self::DECIMALS); |
|
37 | } |
||
38 | |||
39 | 15 | public function add(self $adder): self |
|
40 | { |
||
41 | 15 | $withVat = $this->withVat->add($adder->withVat); |
|
42 | 15 | return self::fromDecimal($withVat); |
|
43 | } |
||
44 | |||
45 | 15 | public function multiply(int $multiplier): self |
|
46 | { |
||
47 | 15 | $withVat = $this->withVat->mul(Decimal::fromInteger($multiplier)); |
|
48 | 15 | return self::fromDecimal($withVat); |
|
49 | } |
||
50 | |||
51 | 17 | private static function fromDecimal(Decimal $withVat): self |
|
54 | } |
||
55 | } |
||
56 |