Completed
Push — master ( b346da...606e51 )
by Alex
02:08
created

TwigConfiguration   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 83.33%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 1
cbo 5
dl 0
loc 53
ccs 20
cts 24
cp 0.8333
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A prepareFilesystem() 0 6 1
A apply() 0 18 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 1
        $injector->prepare(FormattedResponder::class, function (FormattedResponder $responder) {
21 1
            return $responder->withValue(TwigFormatter::class, 1.0);
22 1
        });
23
24 1
        $injector->alias(
25 1
            'Equip\Adr\PayloadInterface',
26
            'Asmaster\EquipTwig\TemplatePayload'
27 1
        );
28
29 1
        $injector->prepare(\Twig_Loader_Filesystem::class, [$this, 'prepareFilesystem']);
30
31 1
        $injector->define(\Twig_Environment::class, [
32 1
            'loader'   => \Twig_Loader_Filesystem::class,
33 1
            ':options' => $this->prepareOptions()
34 1
        ]);
35 1
    }
36
37
    /**
38
     * @param Twig_Loader_Filesystem $loader
39
     */
40
    public function prepareFilesystem(\Twig_Loader_Filesystem $loader)
41
    {
42
        $templates = $this->env->getValue('TWIG_TEMPLATES');
43
44
        $loader->addPath($templates);
45
    }
46
47
    /**
48
     * @return array $options
49
     */
50 1
    public function prepareOptions()
51
    {
52 1
        $env = $this->env;
53
54
        $options = [
55 1
            'debug'            => $env->getValue('TWIG_DEBUG') ?: false,
56 1
            'auto_reload'      => $env->getValue('TWIG_AUTO_RELOAD') ?: true,
57 1
            'strict_variables' => $env->getValue('TWIG_STRICT_VARIABLES') ?: false,
58 1
            'cache'            => $env->getValue('TWIG_CACHE') ?: false
59 1
        ];
60
61 1
        return $options;
62
    }
63
}
64