Completed
Push — master ( 315949...a0e7bf )
by Alex
01:49
created

TwigConfiguration   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 7
c 3
b 0
f 0
lcom 1
cbo 5
dl 0
loc 48
ccs 21
cts 21
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A prepareFilesystem() 0 6 1
A apply() 0 13 1
B prepareOptions() 0 13 5
1
<?php
2
3
namespace Asmaster\EquipTwig\Configuration;
4
5
use Auryn\Injector;
6
use Equip\Configuration\EnvTrait;
7
use Equip\Configuration\ConfigurationInterface;
8
use Equip\Responder\FormattedResponder;
9
use Asmaster\EquipTwig\TwigFormatter;
10
11
class TwigConfiguration implements ConfigurationInterface
12
{
13
    use EnvTrait;
14
15
    /**
16
     * @param Injector $injector
17
     */
18
    public function apply(Injector $injector)
19
    {
20 2
        $injector->prepare(FormattedResponder::class, function (FormattedResponder $responder) {
21 1
            return $responder->withValue(TwigFormatter::class, 1.0);
22 2
        });
23
24 2
        $injector->prepare(\Twig_Loader_Filesystem::class, [$this, 'prepareFilesystem']);
25
26 2
        $injector->define(\Twig_Environment::class, [
27 2
            'loader'   => \Twig_Loader_Filesystem::class,
28 2
            ':options' => $this->prepareOptions()
29 2
        ]);
30 2
    }
31
32
    /**
33
     * @param Twig_Loader_Filesystem $loader
34
     */
35 1
    public function prepareFilesystem(\Twig_Loader_Filesystem $loader)
36
    {
37 1
        $templates = $this->env->getValue('TWIG_TEMPLATES');
38
39 1
        $loader->addPath($templates);
40 1
    }
41
42
    /**
43
     * @return array $options
44
     */
45 2
    public function prepareOptions()
46
    {
47 2
        $env = $this->env;
48
49
        $options = [
50 2
            'debug'            => $env->getValue('TWIG_DEBUG') ?: false,
51 2
            'auto_reload'      => $env->getValue('TWIG_AUTO_RELOAD') ?: true,
52 2
            'strict_variables' => $env->getValue('TWIG_STRICT_VARIABLES') ?: false,
53 2
            'cache'            => $env->getValue('TWIG_CACHE') ?: false
54 2
        ];
55
56 2
        return $options;
57
    }
58
}
59