Total Complexity | 2 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
11 | class LocaleNumberFormatter implements Formatter |
||
12 | { |
||
13 | /** |
||
14 | * @var NumberFormatter |
||
15 | */ |
||
16 | public NumberFormatter $formatter; |
||
17 | |||
18 | /** |
||
19 | * @param int|float|string|null $number |
||
20 | * @param string|null $locale |
||
21 | * @param int $style |
||
22 | * @param string|null $pattern |
||
23 | * @param int $fraction_digits |
||
24 | */ |
||
25 | 7 | public function __construct( |
|
26 | public int|float|string|null $number = null, |
||
27 | public ?string $locale = null, |
||
28 | public int $style = NumberFormatter::DECIMAL, |
||
29 | public ?string $pattern = null, |
||
30 | public int $fraction_digits = 2 |
||
31 | ) { |
||
32 | 7 | $this->locale = $this->locale ?? app()->getLocale(); |
|
|
|||
33 | |||
34 | 7 | $this->formatter = new NumberFormatter( |
|
35 | 7 | $this->locale, |
|
36 | 7 | $this->style, |
|
37 | 7 | $this->pattern |
|
38 | ); |
||
39 | |||
40 | 7 | $this->formatter->setAttribute( |
|
41 | NumberFormatter::FRACTION_DIGITS, |
||
42 | 7 | $this->fraction_digits |
|
43 | ); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * Format the number based on locale. |
||
48 | * |
||
49 | * @param Collection $items |
||
50 | * |
||
51 | * @return string |
||
52 | */ |
||
53 | 7 | public function format(Collection $items): string |
|
57 | ); |
||
58 | } |
||
60 |