MetadataPass::process()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
ccs 9
cts 9
cp 1
rs 9.4285
cc 1
eloc 8
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Happyr\SerializerBundle\DependencyInjection\CompilerPass;
4
5
use Happyr\SerializerBundle\Metadata\Metadata;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
9
/**
10
 * Collect and give the metadata to the normalizers.
11
 *
12
 * @author Tobias Nyholm <[email protected]>
13
 */
14
class MetadataPass implements CompilerPassInterface
15
{
16 23
    public function process(ContainerBuilder $container)
17
    {
18 23
        $provider = $container->get('happyr.serializer.metadata.metadata_provider');
19 23
        $metadata = $provider->getMetadata();
20
21 23
        $normalizerDef = $container->getDefinition('happyr.serializer.normalizer.metadata_aware');
22 23
        $metadataString = Metadata::convertToStrings($metadata);
23 23
        $normalizerDef->replaceArgument(0, $metadataString);
24
25 23
        $normalizerDef = $container->getDefinition('happyr.serializer.denormalizer.metadata_aware');
26 23
        $normalizerDef->replaceArgument(0, $metadataString);
27 23
    }
28
}
29