Conditions | 5 |
Paths | 4 |
Total Lines | 15 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
14 | public static function buildMoney(string $price, string $currency): ?Money |
||
15 | { |
||
16 | if (!is_numeric($price)) { |
||
17 | throw new \InvalidArgumentException('price of the Money must be numeric'); |
||
18 | } |
||
19 | if (is_int($price)) { |
||
|
|||
20 | return new Money($price, new Currency($currency)); |
||
21 | } |
||
22 | if (!is_int($price) && ($price * 100) == ((int) ($price * 100))) { |
||
23 | return new Money((int) $price * 100, new Currency($currency)); |
||
24 | } |
||
25 | list($int, $float) = explode('.', $price); |
||
26 | return new Money( |
||
27 | (int) ($price * (int) (1 . implode(array_fill(0, strlen($float),0)))), |
||
28 | new Currency($currency) |
||
29 | ); |
||
51 |