Completed
Push — master ( d8d25b...3f99c9 )
by Quentin
59s
created

SerializerCompilerPass::process()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 4.0058

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 18
ccs 13
cts 14
cp 0.9286
rs 9.2
cc 4
eloc 10
nc 4
nop 1
crap 4.0058
1
<?php
2
3
namespace Majora\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
/**
10
 * Compiler pass to guess all serializer formats.
11
 */
12
class SerializerCompilerPass implements CompilerPassInterface
13
{
14 2
    public function process(ContainerBuilder $container)
15
    {
16 2
        if (!$container->hasDefinition('majora.serializer')) {
17
            return;
18
        }
19
20 2
        $serializer  = $container->getDefinition('majora.serializer');
21 2
        $handlersDef = $container->findTaggedServiceIds('majora.serialization_handler');
22
23 2
        foreach ($handlersDef as $id => $attributes) {
24 2
            foreach ($attributes as $attribute) {
25 2
                $serializer->addMethodCall('registerFormatHandler', array(
26 2
                    $attribute['format'],
27 2
                    new Reference($id)
28 1
                ));
29 1
            }
30 1
        }
31 2
    }
32
}
33