Completed
Pull Request — master (#33)
by Dominik
04:55
created

DeserializationCompilerPass::process()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 66
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 34
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 4
eloc 41
c 1
b 0
f 1
nc 8
nop 1
dl 0
loc 66
ccs 34
cts 34
cp 1
crap 4
rs 9.264

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Deserialization\DependencyInjection;
6
7
use Chubbyphp\Deserialization\Decoder\Decoder;
8
use Chubbyphp\Deserialization\Decoder\JsonTypeDecoder;
9
use Chubbyphp\Deserialization\Decoder\JsonxTypeDecoder;
10
use Chubbyphp\Deserialization\Decoder\UrlEncodedTypeDecoder;
11
use Chubbyphp\Deserialization\Decoder\XmlTypeDecoder;
12
use Chubbyphp\Deserialization\Decoder\YamlTypeDecoder;
13
use Chubbyphp\Deserialization\Denormalizer\Denormalizer;
14
use Chubbyphp\Deserialization\Denormalizer\DenormalizerObjectMappingRegistry;
15
use Chubbyphp\Deserialization\Deserializer;
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 DeserializationCompilerPass implements CompilerPassInterface
23
{
24
    /**
25
     * @param ContainerBuilder $container
26
     */
27 1
    public function process(ContainerBuilder $container): void
28
    {
29 1
        $container->register('chubbyphp.deserializer', Deserializer::class)->setPublic(true)->setArguments([
30 1
            new Reference('chubbyphp.deserializer.decoder'),
31 1
            new Reference('chubbyphp.deserializer.denormalizer'),
32
        ]);
33
34
        $container
35 1
            ->register('chubbyphp.deserializer.decoder.type.json', JsonTypeDecoder::class)
36 1
            ->addTag('chubbyphp.deserializer.decoder.type')
37
        ;
38
39
        $container
40 1
            ->register('chubbyphp.deserializer.decoder.type.jsonx', JsonxTypeDecoder::class)
41 1
            ->addTag('chubbyphp.deserializer.decoder.type')
42
        ;
43
44
        $container
45 1
            ->register('chubbyphp.deserializer.decoder.type.urlencoded', UrlEncodedTypeDecoder::class)
46 1
            ->addTag('chubbyphp.deserializer.decoder.type')
47
        ;
48
49
        $container
50 1
            ->register('chubbyphp.deserializer.decoder.type.xml', XmlTypeDecoder::class)
51 1
            ->addTag('chubbyphp.deserializer.decoder.type')
52
        ;
53
54 1
        if (class_exists(Yaml::class)) {
55
            $container
56 1
                ->register('chubbyphp.deserializer.decoder.type.yml', YamlTypeDecoder::class)
57 1
                ->addTag('chubbyphp.deserializer.decoder.type')
58
            ;
59
        }
60
61 1
        $decoderTypeReferences = [];
62 1
        foreach ($container->findTaggedServiceIds('chubbyphp.deserializer.decoder.type') as $id => $tags) {
63 1
            $decoderTypeReferences[] = new Reference($id);
64
        }
65
66
        $container
67 1
            ->register('chubbyphp.deserializer.decoder', Decoder::class)
68 1
            ->setPublic(true)
69 1
            ->setArguments([$decoderTypeReferences])
70
        ;
71
72
        $container
73 1
            ->register('chubbyphp.deserializer.denormalizer', Denormalizer::class)
74 1
            ->setPublic(true)
75 1
            ->setArguments([
76 1
                new Reference('chubbyphp.deserializer.denormalizer.objectmappingregistry'),
77 1
                new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE),
78
            ])
79
        ;
80
81 1
        $denormalizerObjectMappingReferences = [];
82 1
        foreach ($container->findTaggedServiceIds('chubbyphp.deserializer.denormalizer.objectmapping') as $id => $tags) {
83 1
            $denormalizerObjectMappingReferences[] = new Reference($id);
84
        }
85
86
        $container
87 1
            ->register(
88 1
                'chubbyphp.deserializer.denormalizer.objectmappingregistry',
89 1
                DenormalizerObjectMappingRegistry::class
90
            )
91 1
            ->setPublic(true)
92 1
            ->setArguments([$denormalizerObjectMappingReferences])
93
        ;
94 1
    }
95
}
96