Passed
Push — master ( 21d838...eb2b9c )
by Dāvis
04:59
created

TemplatingPass::process()   B

Complexity

Conditions 7
Paths 5

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 10
nc 5
nop 1
dl 0
loc 20
rs 8.2222
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
     */
22
    public function process(ContainerBuilder $container)
23
    {
24
        $resources = $container->getParameter('twig.form.resources');
25
26
        $forms = [
27
            'sludio_helper.translatable.enabled' => 'sludio_helper.translatable.template',
28
            'sludio_helper.captcha.enabled' => 'sludio_helper.captcha.client.recaptcha.template',
29
        ];
30
31
        foreach ($forms as $check => $form) {
32
            if ($container->hasParameter($check) && $container->getParameter($check) === true && $container->hasParameter($form)) {
33
                if (false !== ($template = $container->getParameter($form))) {
34
                    if (!in_array($template, $resources)) {
35
                        $resources[] = $template;
36
                    }
37
                }
38
            }
39
        }
40
41
        $container->setParameter('twig.form.resources', $resources);
42
    }
43
}
44