Failed Conditions
Pull Request — experimental/sf (#31)
by Kentaro
06:59
created

NavCompilerPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 20

Duplication

Lines 20
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 6.28

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 20
loc 20
rs 9.6
c 0
b 0
f 0
ccs 4
cts 14
cp 0.2857
crap 6.28
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\EccubeNav;
17
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
20 View Code Duplication
class NavCompilerPass implements CompilerPassInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
{
22
    const NAV_TAG = 'eccube.nav';
23
24 1
    public function process(ContainerBuilder $container)
25
    {
26 1
        $ids = $container->findTaggedServiceIds(self::NAV_TAG);
27 1
        $nav = $container->getParameter('eccube_nav');
28
29 1
        foreach ($ids as $id => $tags) {
30
            $def = $container->getDefinition($id);
31
            $class = $container->getParameterBag()->resolveValue($def->getClass());
32
            if (!is_subclass_of($class, EccubeNav::class)) {
33
                throw new \InvalidArgumentException(
34
                    sprintf('Service "%s" must implement interface "%s".', $id, EccubeNav::class));
35
            }
36
37
            /** @var $class EccubeNav */
38
            $addNav = $class::getNav();
39
            $nav = array_replace_recursive($nav, $addNav);
40
        }
41
42
        $container->setParameter('eccube_nav', $nav);
43
    }
44
}
45