| Total Complexity | 5 |
| Total Lines | 36 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | class TemplateRenderer |
||
| 10 | { |
||
| 11 | 2 | public function __construct( |
|
| 12 | private RendererAdapterInterface $renderer, |
||
| 13 | private string $extension = 'html', |
||
| 14 | ) { |
||
| 15 | 2 | $this->extension = ltrim($extension, '.'); |
|
| 16 | } |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Check whether a template exists. |
||
| 20 | */ |
||
| 21 | 2 | public function exists(string $name): bool |
|
| 22 | { |
||
| 23 | 2 | $template = $this->normalizeTemplate($name); |
|
| 24 | 2 | return $this->renderer->exists($template); |
|
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Render a template with the given parameters. |
||
| 29 | */ |
||
| 30 | 2 | public function render(string $name, array $params = []): string |
|
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Normalize the template's name. |
||
| 38 | */ |
||
| 39 | 2 | private function normalizeTemplate(string $name): string |
|
| 47 |