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