TemplatingPass::process()   B
last analyzed

Complexity

Conditions 7
Paths 4

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 9
nc 4
nop 1
dl 0
loc 18
rs 8.8333
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the SludioHelperBundle package.
4
 *
5
 * @author Dāvis Zālītis <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Sludio\HelperBundle\DependencyInjection\Compiler;
12
13
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
16
class TemplatingPass implements CompilerPassInterface
17
{
18
19
    /**
20
     * {@inheritdoc}
21
     * @throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
22
     */
23
    public function process(ContainerBuilder $container)
24
    {
25
        $resources = $container->getParameter('twig.form.resources');
26
27
        $forms = [
28
            'sludio_helper.translatable.enabled' => 'sludio_helper.translatable.template',
29
            'sludio_helper.captcha.enabled' => 'sludio_helper.captcha.client.recaptcha.template',
30
        ];
31
32
        foreach ($forms as $check => $form) {
33
            if ($container->hasParameter($check) && $container->getParameter($check) === true && $container->hasParameter($form) && false !== ($template = $container->getParameter($form))) {
34
                if (!\in_array($template, $resources, false)) {
35
                    $resources[] = $template;
36
                }
37
            }
38
        }
39
40
        $container->setParameter('twig.form.resources', $resources);
41
    }
42
}
43