Completed
Push — master ( 7c9eb0...a92430 )
by Thomas
13s
created

AbstractOverrideTwigConfigAction::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the ekino Drupal Debug project.
7
 *
8
 * (c) ekino
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Ekino\Drupal\Debug\Action;
15
16
use Ekino\Drupal\Debug\Exception\NotSupportedException;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
19
abstract class AbstractOverrideTwigConfigAction implements CompilerPassActionInterface
20
{
21
    /**
22
     * @var string
23
     */
24
    const TWIG_CONFIG_PARAMETER_NAME = 'twig.config';
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 4
    public function process(ContainerBuilder $container): void
30
    {
31 4
        if (!$container->hasParameter(self::TWIG_CONFIG_PARAMETER_NAME)) {
32 1
            throw new NotSupportedException(\sprintf('The "%s" parameter should already be set in the container builder.', self::TWIG_CONFIG_PARAMETER_NAME));
33
        }
34
35 3
        $container->setParameter(self::TWIG_CONFIG_PARAMETER_NAME, \array_merge($container->getParameter(self::TWIG_CONFIG_PARAMETER_NAME), $this->getOverrides()));
36 3
    }
37
38
    /**
39
     * @return array
40
     */
41
    abstract protected function getOverrides(): array;
42
}
43