Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
TwigEngine
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 canRender
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Engelsystem\Renderer;
6
7use Twig\Environment as Twig;
8use Twig\Error\LoaderError as LoaderError;
9use Twig\Error\RuntimeError as RuntimeError;
10use Twig\Error\SyntaxError as SyntaxError;
11
12class TwigEngine extends Engine
13{
14    public function __construct(protected Twig $twig)
15    {
16    }
17
18    /**
19     * Render a twig template
20     *
21     * @throws LoaderError|RuntimeError|SyntaxError
22     */
23    public function get(string $path, array $data = []): string
24    {
25        $data = array_replace_recursive($this->sharedData, $data);
26
27        return $this->twig->render($path, $data);
28    }
29
30    public function canRender(string $path): bool
31    {
32        return $this->twig->getLoader()->exists($path);
33    }
34}