TemplateEngine::render()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 10
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