TwigTemplatesContainerConfigurator   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 2
dl 0
loc 29
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A configureContainer() 0 20 1
1
<?php declare(strict_types=1);
2
3
namespace Limoncello\Templates\Package;
4
5
/**
6
 * Copyright 2015-2019 [email protected]
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 * http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
21
use Limoncello\Contracts\Application\ContainerConfiguratorInterface;
22
use Limoncello\Contracts\Container\ContainerInterface as LimoncelloContainerInterface;
23
use Limoncello\Contracts\Settings\SettingsProviderInterface;
24
use Limoncello\Contracts\Templates\TemplatesInterface;
25
use Limoncello\Templates\Contracts\TemplatesCacheInterface;
26
use Limoncello\Templates\Package\TemplatesSettings as C;
27
use Limoncello\Templates\TwigTemplates;
28
use Psr\Container\ContainerInterface as PsrContainerInterface;
29
30
/**
31
 * @package Limoncello\Templates
32
 */
33
class TwigTemplatesContainerConfigurator implements ContainerConfiguratorInterface
34
{
35
    /** @var callable */
36
    const CONFIGURATOR = [self::class, self::CONTAINER_METHOD_NAME];
37
38
    /**
39
     * @inheritdoc
40
     */
41 1
    public static function configureContainer(LimoncelloContainerInterface $container): void
42
    {
43
        $container[TemplatesInterface::class] = function (PsrContainerInterface $container): TemplatesInterface {
44 1
            $settings  = $container->get(SettingsProviderInterface::class)->get(C::class);
45 1
            $templates = new TwigTemplates(
46 1
                $settings[C::KEY_APP_ROOT_FOLDER],
47 1
                $settings[C::KEY_TEMPLATES_FOLDER],
48 1
                $settings[C::KEY_CACHE_FOLDER] ?? null,
49 1
                $settings[C::KEY_IS_DEBUG] ?? false,
50 1
                $settings[C::KEY_IS_AUTO_RELOAD] ?? false
51
            );
52
53 1
            return $templates;
54
        };
55
56 1
        $container[TemplatesCacheInterface::class] =
57
            function (PsrContainerInterface $container): TemplatesCacheInterface {
58 1
                return $container->get(TemplatesInterface::class);
59
            };
60
    }
61
}
62