Total Complexity | 2 |
Total Lines | 42 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
11 | class IntlMoneyFormatter |
||
12 | { |
||
13 | use BladeDirectiveHelpers; |
||
14 | |||
15 | /** |
||
16 | * Calls the format() method on the IntlMoneyFormatter with the given |
||
17 | * amount of cents, currency code and locale. |
||
18 | * |
||
19 | * @param integer $cents |
||
20 | * @param string $code |
||
21 | * @param string $locale |
||
22 | * @return string |
||
23 | */ |
||
24 | public static function handler(int $cents, string $code, string $locale): string |
||
25 | { |
||
26 | $formatter = new BaseFormatter( |
||
27 | new NumberFormatter($locale, NumberFormatter::CURRENCY), |
||
28 | new ISOCurrencies |
||
29 | ); |
||
30 | |||
31 | $money = Money::$code($cents); |
||
32 | |||
33 | return $formatter->format($money); |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * Registers a handler for the money formatter. |
||
38 | * |
||
39 | * @param string $name |
||
40 | * @param string $code |
||
41 | * @param string $locale |
||
42 | * @return void |
||
43 | */ |
||
44 | public static function directive(string $name = 'money', string $code = 'EUR', string $locale = 'nl_NL') |
||
53 | }); |
||
54 | } |
||
56 |