Failed Conditions
Branch experimental/sf (68db07)
by Kentaro
42:17 queued 33:39
created

TwigBlockPass::process()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4.0582

Importance

Changes 0
Metric Value
cc 4
nc 4
nop 1
dl 0
loc 22
rs 9.568
c 0
b 0
f 0
ccs 11
cts 13
cp 0.8462
crap 4.0582
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
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 Eccube\DependencyInjection\Compiler;
15
16
use Eccube\Common\EccubeTwigBlock;
17
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
20
class TwigBlockPass implements CompilerPassInterface
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
21
{
22
    const TWIG_BLOCK_TAG = 'eccube.twig_block';
23
24 1
    public function process(ContainerBuilder $container)
25
    {
26 1
        $ids = $container->findTaggedServiceIds(self::TWIG_BLOCK_TAG);
27 1
        $templates = $container->getParameter('eccube_twig_block_templates');
28
29 1
        foreach ($ids as $id => $tags) {
30 1
            $def = $container->getDefinition($id);
31 1
            $class = $container->getParameterBag()->resolveValue($def->getClass());
32 1
            if (!is_subclass_of($class, EccubeTwigBlock::class)) {
33
                throw new \InvalidArgumentException(
34
                    sprintf('Service "%s" must implement interface "%s".', $id, EccubeTwigBlock::class));
35
            }
36
37
            /** @var $class EccubeTwigBlock */
38 1
            $blocks = $class::getTwigBlock();
39 1
            foreach ($blocks as $block) {
40 1
                $templates[] = $block;
41
            }
42
        }
43
44 1
        $container->setParameter('eccube_twig_block_templates', $templates);
45
    }
46
}
47