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

TemplateEngine   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A render() 0 6 2
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