Completed
Pull Request — master (#40)
by Francesco
03:00
created

ParserCompilerPass   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 0
cbo 3
dl 0
loc 29
ccs 12
cts 12
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 18 2
1
<?php
2
3
namespace Paraunit\Parser;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
/**
10
 * Class ParserCompilerPass
11
 */
12
class ParserCompilerPass implements CompilerPassInterface
13
{
14
15
    const TAGGED_SERVICES = 'log_parser';
16
    const TO_COMPILE      = 'paraunit.parser.json_log_parser';
17
18
    /**
19
     * @inheritdoc
20
     */
21 39
    public function process(ContainerBuilder $container)
22
    {
23
24 39
        $taggedServices = $container->findTaggedServiceIds(self::TAGGED_SERVICES);
25
26 39
        uasort(
27 39
            $taggedServices,
28 39
            function ($a, $b) {
29 39
                return $a[0]['priority'] > $b[0]['priority'];
30
            }
31 39
        );
32
33 39
        foreach ($taggedServices as $id => $taggedService) {
34 39
            $service = $container->getDefinition(self::TO_COMPILE);
35 39
            $service->addMethodCall('addParser', array(new Reference($id)));
36 39
        }
37
38 39
    }
39
40
}
41