Completed
Push — master ( 42f99d...2335a8 )
by Nikola
18:20 queued 03:48
created

ProcessorsCompilerPass::process()   B

Complexity

Conditions 6
Paths 9

Size

Total Lines 24
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 24
rs 8.5125
cc 6
eloc 11
nc 9
nop 1
1
<?php
2
3
namespace RunOpenCode\Bundle\ExchangeRate\DependencyInjection\CompilerPass;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
/**
10
 * Class ProcessorsCompilerPass
11
 *
12
 * @package RunOpenCode\Bundle\ExchangeRate\DependencyInjection\CompilerPass
13
 */
14
class ProcessorsCompilerPass implements CompilerPassInterface
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function process(ContainerBuilder $container)
20
    {
21
        if ($container->hasDefinition('run_open_code.exchange_rate.registry.processors')) {
22
23
            $definition = $container->getDefinition('run_open_code.exchange_rate.registry.processors');
24
25
            $processors = array();
26
27
            foreach ($container->findTaggedServiceIds('run_open_code.exchange_rate.processor') as $id => $tags) {
28
29
                foreach ($tags as $attributes) {
30
                    $processors[$id] = !empty($attributes['priority']) ? (int)$attributes['priority'] : 0;
31
                }
32
            }
33
34
            asort($processors);
35
36
            foreach ($processors as $id => $processor) {
37
                $definition->addMethodCall('add', array(
38
                    new Reference($id)
39
                ));
40
            }
41
        }
42
    }
43
}
44