Template   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 45
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A render() 0 6 1
A createTwigEnvironment() 0 23 1
1
<?php
2
3
namespace Spatie\SchemaOrg\Generator\Writer;
4
5
use Twig_Environment;
6
use Twig_Loader_Filesystem;
7
use Twig_SimpleFilter;
8
9
class Template
10
{
11
    /** @var \Twig_Environment */
12
    protected $twig;
13
14
    /** @var string */
15
    protected $template;
16
17
    public function __construct(string $template)
18
    {
19
        $this->template = $template;
20
        $this->twig = $this->createTwigEnvironment();
21
    }
22
23
    public function render(array $context): string
24
    {
25
        return $this->twig
26
            ->load($this->template)
27
            ->render($context);
28
    }
29
30
    protected function createTwigEnvironment(): Twig_Environment
31
    {
32
        $loader = new Twig_Loader_Filesystem(__DIR__.'/../templates/twig');
33
34
        $twig = new Twig_Environment($loader, [
35
            'cache' => false,
36
            'autoescape' => false,
37
        ]);
38
39
        $twig->addFilter(
40
            new Twig_SimpleFilter('doc', [Filters::class, 'doc'], ['is_variadic' => true])
41
        );
42
43
        $twig->addFilter(
44
            new Twig_SimpleFilter('param', [Filters::class, 'param'])
45
        );
46
47
        $twig->addFilter(
48
            new Twig_SimpleFilter('lcfirst', [Filters::class, 'lcfirst'])
49
        );
50
51
        return $twig;
52
    }
53
}
54