Completed
Pull Request — master (#7)
by Dominik
07:16
created

SerializationCompilerPass   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 44
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 38 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Serialization\DependencyInjection;
6
7
use Chubbyphp\Serialization\Encoder\Encoder;
8
use Chubbyphp\Serialization\Normalizer\Normalizer;
9
use Chubbyphp\Serialization\Normalizer\NormalizerObjectMappingRegistry;
10
use Chubbyphp\Serialization\Serializer;
11
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
12
use Symfony\Component\DependencyInjection\ContainerBuilder;
13
use Symfony\Component\DependencyInjection\ContainerInterface;
14
use Symfony\Component\DependencyInjection\Reference;
15
16
final class SerializationCompilerPass implements CompilerPassInterface
17
{
18
    /**
19
     * @param ContainerBuilder $container
20
     */
21 1
    public function process(ContainerBuilder $container)
22
    {
23 1
        $container->register('chubbyphp.serializer', Serializer::class)->setPublic(true)->setArguments([
24 1
            new Reference('chubbyphp.serializer.normalizer'),
25 1
            new Reference('chubbyphp.serializer.encoder'),
26
        ]);
27
28
        $container
29 1
            ->register('chubbyphp.serializer.normalizer', Normalizer::class)
30 1
            ->setPublic(true)
31 1
            ->setArguments([
32 1
                new Reference('chubbyphp.serializer.normalizer.objectmappingregistry'),
33 1
                new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE),
34
            ]);
35
36 1
        $normalizerObjectMappingReferences = [];
37 1
        foreach ($container->findTaggedServiceIds('serializer.normalizer.objectmapping') as $id => $tags) {
38 1
            $normalizerObjectMappingReferences[] = new Reference($id);
39
        }
40
41
        $container
42 1
            ->register(
43 1
                'chubbyphp.serializer.normalizer.objectmappingregistry',
44 1
                NormalizerObjectMappingRegistry::class
45
            )
46 1
            ->setPublic(true)
47 1
            ->setArguments([$normalizerObjectMappingReferences]);
48
49 1
        $encoderTypeReferences = [];
50 1
        foreach ($container->findTaggedServiceIds('chubbyphp.serializer.encoder.type') as $id => $tags) {
51 1
            $encoderTypeReferences[] = new Reference($id);
52
        }
53
54
        $container
55 1
            ->register('chubbyphp.serializer.encoder', Encoder::class)
56 1
            ->setPublic(true)
57 1
            ->setArguments([$encoderTypeReferences]);
58 1
    }
59
}
60