InstallItemPass::process()   B
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 14
cp 0
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 11
nc 3
nop 1
crap 30
1
<?php
2
/**
3
 * AnimeDb package.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 * @license   http://opensource.org/licenses/GPL-3.0 GPL v3
8
 */
9
10
namespace AnimeDb\Bundle\CatalogBundle\DependencyInjection\Compiler;
11
12
use Symfony\Component\DependencyInjection\ContainerBuilder;
13
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
14
use Symfony\Component\DependencyInjection\Reference;
15
16
/**
17
 * Install item compiler pass.
18
 *
19
 * @author  Peter Gribanov <[email protected]>
20
 */
21
class InstallItemPass implements CompilerPassInterface
22
{
23
    /**
24
     * @param ContainerBuilder $container
25
     */
26
    public function process(ContainerBuilder $container)
27
    {
28
        if (
29
            $container->getParameter('anime_db.catalog.installed') ||
30
            !$container->has('anime_db.install.item.chain')
31
        ) {
32
            return;
33
        }
34
35
        $definition = $container->findDefinition('anime_db.install.item.chain');
36
        $taggedServices = $container->findTaggedServiceIds('anime_db.install_item');
37
        foreach ($taggedServices as $id => $attributes) {
38
            $definition->addMethodCall(
39
                !empty($attributes[0]['debug']) ? 'addDebugItem' : 'addPublicItem',
40
                [new Reference($id)]
41
            );
42
        }
43
    }
44
}
45