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

ParserCompilerPass::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 18
ccs 12
cts 12
cp 1
rs 9.4285
cc 2
eloc 9
nc 2
nop 1
crap 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