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

ProcessorsCompilerPass   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 30
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 24 6
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