Conditions | 7 |
Paths | 11 |
Total Lines | 28 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Tests | 17 |
CRAP Score | 7.0084 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
22 | 176 | public function format(string $message, array $parameters, string $locale = 'en-US'): string |
|
23 | { |
||
24 | 176 | if ($parameters === []) { |
|
25 | 114 | return $message; |
|
26 | } |
||
27 | |||
28 | 78 | $replacements = []; |
|
29 | |||
30 | 78 | foreach ($parameters as $key => $value) { |
|
31 | 78 | if (is_array($value)) { |
|
32 | 1 | $value = 'array'; |
|
33 | 77 | } elseif (is_object($value)) { |
|
34 | 2 | $value = 'object'; |
|
35 | 75 | } elseif (is_resource($value)) { |
|
36 | 1 | $value = 'resource'; |
|
37 | } |
||
38 | 78 | $replacements[$key] = $value; |
|
39 | } |
||
40 | |||
41 | 78 | $locale = $this->locale ?? $locale; |
|
42 | 78 | $formatter = new MessageFormatter($locale, $message); |
|
43 | 78 | $result = $formatter->format($replacements); |
|
44 | |||
45 | 78 | if ($result === false) { |
|
46 | return $message; |
||
47 | } |
||
48 | |||
49 | 78 | return $result; |
|
50 | } |
||
66 |