Passed
Push — develop ( 212af8...a3b9d2 )
by Brent
02:06
created

TwigRenderer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 29
c 0
b 0
f 0
ccs 14
cts 14
cp 1
rs 10
wmc 5
lcom 0
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A make() 0 4 1
A renderTemplate() 0 4 1
A customExtension() 0 4 1
1
<?php
2
3
namespace Stitcher\Renderer;
4
5
use Stitcher\Renderer;
6
use Symfony\Component\Filesystem\Filesystem;
7
use Twig_Environment;
8
9
class TwigRenderer extends Twig_Environment implements Renderer
10
{
11 14
    public function __construct(string $templateDirectory)
12
    {
13 14
        $fs = new Filesystem();
14 14
        if (! $fs->exists($templateDirectory)) {
15 2
            $fs->mkdir($templateDirectory);
16
        }
17
18 14
        $loader = new \Twig_Loader_Filesystem($templateDirectory);
19
20 14
        parent::__construct($loader);
21 14
    }
22
23 14
    public static function make(string $templateDirectory): TwigRenderer
24
    {
25 14
        return new self($templateDirectory);
26
    }
27
28 12
    public function renderTemplate(string $path, array $variables): string
29
    {
30 12
        return $this->render($path, $variables);
31
    }
32
33 12
    public function customExtension(Extension $extension): void
34
    {
35 12
        $this->addGlobal($extension->name(), $extension);
36 12
    }
37
}
38