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

TwigRenderer::customExtension()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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