Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
14.29% |
1 / 7 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Price | |
14.29% |
1 / 7 |
|
50.00% |
1 / 2 |
20.74 | |
0.00% |
0 / 1 |
| toCharmPrice | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
20 | |||
| getNumberOfDecimals | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Apie\Core\ValueObjects; |
| 4 | |
| 5 | class Price extends Decimal |
| 6 | { |
| 7 | public function toCharmPrice(int $ending = 95): self |
| 8 | { |
| 9 | if ($ending < 0 || $ending > 99) { |
| 10 | throw new \InvalidArgumentException('Ending must be between 0 and 99.'); |
| 11 | } |
| 12 | |
| 13 | $integer = $this->integerPart; |
| 14 | |
| 15 | if ((int) $this->decimalPart < $ending) { |
| 16 | $integer--; |
| 17 | } |
| 18 | |
| 19 | return self::fromNative(sprintf('%d.%02d', $integer, $ending)); |
| 20 | } |
| 21 | |
| 22 | public static function getNumberOfDecimals(): int |
| 23 | { |
| 24 | return 2; |
| 25 | } |
| 26 | } |