Conditions | 5 |
Paths | 4 |
Total Lines | 15 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
32 | public static function buildQuantityByMoneyPrice(string $price, string $unit, string $quantity): ?Quantity |
||
33 | { |
||
34 | if (!is_numeric($price)) { |
||
35 | throw new \InvalidArgumentException('price of the Money must be numeric'); |
||
36 | } |
||
37 | if (is_int($price)) { |
||
38 | return Quantity::create(Unit::create($unit), $quantity); |
||
39 | } |
||
40 | if (!is_int((int) $price) && ($price * 100) == ((int) ($price * 100))) { |
||
41 | return Quantity::create(Unit::create($unit), $quantity * 100); |
||
42 | } |
||
43 | list($int, $float) = explode('.', $price); |
||
44 | return Quantity::create( |
||
45 | Unit::create($unit), |
||
46 | $quantity * (int) (1 . implode(array_fill(0, strlen($float),0))) |
||
47 | ); |
||
51 |