Passed
Push — master ( 1ba30a...8ac47c )
by Luis
01:05 queued 12s
created

TemplateEngine   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 23
ccs 10
cts 10
cp 1
rs 10
c 2
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A render() 0 6 2
1
<?php declare(strict_types=1);
2
/**
3
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
4
 */
5
6
namespace PhUml\Templates;
7
8
use Twig\Environment as Twig;
0 ignored issues
show
Bug introduced by
The type Twig\Environment was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Twig\Error\LoaderError;
0 ignored issues
show
Bug introduced by
The type Twig\Error\LoaderError was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Twig\Error\RuntimeError;
0 ignored issues
show
Bug introduced by
The type Twig\Error\RuntimeError was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Twig\Error\SyntaxError;
0 ignored issues
show
Bug introduced by
The type Twig\Error\SyntaxError was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Twig\Loader\FilesystemLoader;
0 ignored issues
show
Bug introduced by
The type Twig\Loader\FilesystemLoader was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Twig\TwigFilter as Filter;
0 ignored issues
show
Bug introduced by
The type Twig\TwigFilter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
15
/** @noRector \Rector\Privatization\Rector\Class_\FinalizeClassesWithoutChildrenRector */
16
class TemplateEngine
17
{
18
    private readonly Twig $twig;
19
20 41
    public function __construct(Twig $twig = null)
21
    {
22 41
        $this->twig = $twig ?? new Twig(
0 ignored issues
show
Bug introduced by
The property twig is declared read-only in PhUml\Templates\TemplateEngine.
Loading history...
23 39
            new FilesystemLoader(__DIR__ . '/../resources/templates'),
24 39
            ['strict_variables' => true]
25
        );
26 41
        $this->twig->addFilter(new Filter(
27
            'whitespace',
28 41
            static fn (string $html): ?string => preg_replace('/\s\s+/', '', $html)
29
        ));
30
    }
31
32
    /** @param mixed[] $values */
33 32
    public function render(string $template, array $values): string
34
    {
35
        try {
36 32
            return $this->twig->render($template, $values);
37 1
        } catch (LoaderError | RuntimeError  | SyntaxError $e) {
38 1
            throw new TemplateFailure($e);
39
        }
40
    }
41
}
42