Code Duplication    Length = 25-27 lines in 2 locations

src/Eccube/DependencyInjection/Compiler/NavCompilerPass.php 1 location

@@ 20-44 (lines=25) @@
17
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
20
class NavCompilerPass implements CompilerPassInterface
21
{
22
    const NAV_TAG = 'eccube.nav';
23
24
    public function process(ContainerBuilder $container)
25
    {
26
        $ids = $container->findTaggedServiceIds(self::NAV_TAG);
27
        $nav = $container->getParameter('eccube_nav');
28
29
        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

src/Eccube/DependencyInjection/Compiler/TwigBlockPass.php 1 location

@@ 20-46 (lines=27) @@
17
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
20
class TwigBlockPass implements CompilerPassInterface
21
{
22
    const TWIG_BLOCK_TAG = 'eccube.twig_block';
23
24
    public function process(ContainerBuilder $container)
25
    {
26
        $ids = $container->findTaggedServiceIds(self::TWIG_BLOCK_TAG);
27
        $templates = $container->getParameter('eccube_twig_block_templates');
28
29
        foreach ($ids as $id => $tags) {
30
            $def = $container->getDefinition($id);
31
            $class = $container->getParameterBag()->resolveValue($def->getClass());
32
            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
            $blocks = $class::getTwigBlock();
39
            foreach ($blocks as $block) {
40
                $templates[] = $block;
41
            }
42
        }
43
44
        $container->setParameter('eccube_twig_block_templates', $templates);
45
    }
46
}
47