SerializationCompilerPass   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 42
dl 0
loc 68
ccs 31
cts 31
cp 1
rs 10
c 1
b 0
f 1
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 66 4
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\Encoder\JsonTypeEncoder;
9
use Chubbyphp\Serialization\Encoder\JsonxTypeEncoder;
10
use Chubbyphp\Serialization\Encoder\UrlEncodedTypeEncoder;
11
use Chubbyphp\Serialization\Encoder\XmlTypeEncoder;
12
use Chubbyphp\Serialization\Encoder\YamlTypeEncoder;
13
use Chubbyphp\Serialization\Normalizer\Normalizer;
14
use Chubbyphp\Serialization\Normalizer\NormalizerObjectMappingRegistry;
15
use Chubbyphp\Serialization\Serializer;
16
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\DependencyInjection\ContainerInterface;
19
use Symfony\Component\DependencyInjection\Reference;
20
use Symfony\Component\Yaml\Yaml;
21
22
final class SerializationCompilerPass implements CompilerPassInterface
23
{
24
    public function process(ContainerBuilder $container): void
25
    {
26
        $container->register('chubbyphp.serializer', Serializer::class)->setPublic(true)->setArguments([
27 1
            new Reference('chubbyphp.serializer.normalizer'),
28
            new Reference('chubbyphp.serializer.encoder'),
29 1
        ]);
30 1
31 1
        $container
32
            ->register('chubbyphp.serializer.normalizer', Normalizer::class)
33
            ->setPublic(true)
34
            ->setArguments([
35 1
                new Reference('chubbyphp.serializer.normalizer.objectmappingregistry'),
36 1
                new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE),
37 1
            ])
38 1
        ;
39 1
40
        $normalizerObjectMappingReferences = [];
41
        foreach ($container->findTaggedServiceIds('chubbyphp.serializer.normalizer.objectmapping') as $id => $tags) {
42
            $normalizerObjectMappingReferences[] = new Reference($id);
43 1
        }
44 1
45 1
        $container
46
            ->register(
47
                'chubbyphp.serializer.normalizer.objectmappingregistry',
48
                NormalizerObjectMappingRegistry::class
49 1
            )
50 1
            ->setPublic(true)
51 1
            ->setArguments([$normalizerObjectMappingReferences])
52
        ;
53 1
54 1
        $container
55
            ->register('chubbyphp.serializer.encoder.type.json', JsonTypeEncoder::class)
56
            ->addTag('chubbyphp.serializer.encoder.type')
57
        ;
58 1
59 1
        $container
60
            ->register('chubbyphp.serializer.encoder.type.jsonx', JsonxTypeEncoder::class)
61
            ->addTag('chubbyphp.serializer.encoder.type')
62
        ;
63 1
64 1
        $container
65
            ->register('chubbyphp.serializer.encoder.type.urlencoded', UrlEncodedTypeEncoder::class)
66
            ->addTag('chubbyphp.serializer.encoder.type')
67
        ;
68 1
69 1
        $container
70
            ->register('chubbyphp.serializer.encoder.type.xml', XmlTypeEncoder::class)
71
            ->addTag('chubbyphp.serializer.encoder.type')
72
        ;
73 1
74 1
        if (class_exists(Yaml::class)) {
75
            $container
76
            ->register('chubbyphp.serializer.encoder.type.yaml', YamlTypeEncoder::class)
77 1
            ->addTag('chubbyphp.serializer.encoder.type')
78
            ;
79 1
        }
80 1
81
        $encoderTypeReferences = [];
82
        foreach ($container->findTaggedServiceIds('chubbyphp.serializer.encoder.type') as $id => $tags) {
83
            $encoderTypeReferences[] = new Reference($id);
84 1
        }
85 1
86 1
        $container
87
            ->register('chubbyphp.serializer.encoder', Encoder::class)
88
            ->setPublic(true)
89
            ->setArguments([$encoderTypeReferences])
90 1
        ;
91 1
    }
92
}
93