Conditions | 3 |
Paths | 3 |
Total Lines | 16 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Tests | 9 |
CRAP Score | 3 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
13 | 24 | public function translate(string $text, string $pattern = '/[^{{\}\}]+(?=}})/'): string |
|
14 | { |
||
15 | 24 | preg_match_all($pattern, $text, $matches); |
|
16 | |||
17 | 24 | if (0 === \count($matches[0])) { |
|
18 | 23 | return $text; |
|
19 | } |
||
20 | |||
21 | 2 | $replace_vars = []; |
|
22 | |||
23 | 2 | foreach ($matches[0] as $match) { |
|
24 | 2 | $var = Str::slug($match, '_'); |
|
25 | 2 | $replace_vars["{{{$match}}}"] = $this->store->get($var, "{{$var}}"); |
|
26 | } |
||
27 | |||
28 | 2 | return strtr($text, $replace_vars); |
|
29 | } |
||
42 |