| Conditions | 3 |
| Paths | 3 |
| Total Lines | 16 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 3 |
| Changes | 0 | ||
| 1 | <?php |
||
| 33 | 2 | public static function translate(CacheContract $cache, string $prefix, string $text, string $pattern = '/[^{\}]+(?=})/'): string |
|
| 34 | { |
||
| 35 | 2 | preg_match_all($pattern, $text, $matches); |
|
| 36 | |||
| 37 | 2 | if (0 === \count($matches[0])) { |
|
| 38 | 1 | return $text; |
|
| 39 | } |
||
| 40 | |||
| 41 | 2 | $replace_vars = []; |
|
| 42 | |||
| 43 | 2 | foreach ($matches[0] as $match) { |
|
| 44 | 2 | $var = Str::slug($match, '_'); |
|
| 45 | 2 | $replace_vars["{{$match}}"] = $cache->get("{$prefix}_{$var}", "{{$var}}"); |
|
| 46 | } |
||
| 47 | |||
| 48 | 2 | return strtr($text, $replace_vars); |
|
| 49 | } |
||
| 51 |