Passed
Push — master ( d09870...716959 )
by Luis
02:38
created

TemplateEngine::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * PHP version 7.1
4
 *
5
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
6
 */
7
8
namespace PhUml\Templates;
9
10
use Twig_Environment as Twig;
11
use Twig_Error_Loader as LoaderError;
12
use Twig_Error_Runtime as RuntimeError;
13
use Twig_Error_Syntax as SyntaxError;
14
use Twig_Loader_Filesystem as FileSystemLoader;
15
16
class TemplateEngine
17
{
18
    /** @var Twig */
19
    private $twig;
20
21 75
    public function __construct(Twig $twig = null)
22
    {
23 75
        $this->twig = $twig ?? new Twig(new FileSystemLoader(__DIR__ . '/../resources/templates'));
24 75
    }
25
26 45
    public function render($template, array $values): string
27
    {
28
        try {
29 45
            return $this->twig->render($template, $values);
30 3
        } catch (LoaderError | RuntimeError  | SyntaxError $e) {
31 3
            throw new TemplateFailure($e);
32
        }
33
    }
34
}
35