| Conditions | 2 |
| Paths | 2 |
| Total Lines | 15 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 2 |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 19 | 1 | public function render(string $filename, array $data = []): string |
|
| 20 | { |
||
| 21 | 1 | $templateContents = file_get_contents($filename); |
|
| 22 | 1 | preg_match_all('/{{ *([a-zA-Z_0-9-]*)? *}}/', $templateContents, $templateVars); |
|
| 23 | |||
| 24 | $templateVarNames = array_unique(array_map(function ($item) { |
||
| 25 | 1 | return trim($item); |
|
| 26 | 1 | }, $templateVars[1])); |
|
| 27 | |||
| 28 | 1 | $tokenized = preg_replace('/{{ *([a-zA-Z_0-9-]*)? *}}/', '{{$1}}', $templateContents); |
|
| 29 | |||
| 30 | 1 | foreach ($templateVarNames as $toReplace) { |
|
| 31 | 1 | $tokenized = str_replace('{{' . $toReplace . '}}', $data[$toReplace] ?? '', $tokenized); |
|
| 32 | } |
||
| 33 | 1 | return $tokenized; |
|
| 34 | } |
||
| 36 |