ProcessorsCompilerPass::process()   B
last analyzed

Complexity

Conditions 6
Paths 9

Size

Total Lines 24
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 12
cts 12
cp 1
rs 8.5125
c 0
b 0
f 0
cc 6
eloc 11
nc 9
nop 1
crap 6
1
<?php
2
/*
3
 * This file is part of the Exchange Rate Bundle, an RunOpenCode project.
4
 *
5
 * (c) 2017 RunOpenCode
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace RunOpenCode\Bundle\ExchangeRate\DependencyInjection\CompilerPass;
11
12
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
13
use Symfony\Component\DependencyInjection\ContainerBuilder;
14
use Symfony\Component\DependencyInjection\Reference;
15
16
/**
17
 * Class ProcessorsCompilerPass
18
 *
19
 * Compiler pass for processors.
20
 *
21
 * @package RunOpenCode\Bundle\ExchangeRate\DependencyInjection\CompilerPass
22
 */
23
class ProcessorsCompilerPass implements CompilerPassInterface
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28 2
    public function process(ContainerBuilder $container)
29
    {
30 2
        if ($container->has('runopencode.exchange_rate.registry.processors')) {
31
32 1
            $definition = $container->findDefinition('runopencode.exchange_rate.registry.processors');
33
34 1
            $processors = array();
35
36 1
            foreach ($container->findTaggedServiceIds('runopencode.exchange_rate.processor') as $id => $tags) {
37
38 1
                foreach ($tags as $attributes) {
39 1
                    $processors[$id] = !empty($attributes['priority']) ? (int)$attributes['priority'] : 0;
40
                }
41
            }
42
43 1
            asort($processors);
44
45 1
            foreach ($processors as $id => $processor) {
46 1
                $definition->addMethodCall('add', array(
47 1
                    new Reference($id)
48
                ));
49
            }
50
        }
51 2
    }
52
}
53