SerializationProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 26
dl 0
loc 46
ccs 22
cts 22
cp 1
rs 10
c 2
b 0
f 1
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 44 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Serialization\Provider;
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 Pimple\Container;
17
use Pimple\ServiceProviderInterface;
18
use Symfony\Component\Yaml\Yaml;
19
20
final class SerializationProvider implements ServiceProviderInterface
21
{
22
    public function register(Container $container): void
23
    {
24
        $container['serializer'] = function () use ($container) {
25
            return new Serializer($container['serializer.normalizer'], $container['serializer.encoder']);
26
        };
27 1
28 1
        $container['serializer.normalizer'] = function () use ($container) {
29
            return new Normalizer(
30
                $container['serializer.normalizer.objectmappingregistry'],
31 1
                $container['logger'] ?? null
32 1
            );
33 1
        };
34 1
35
        $container['serializer.normalizer.objectmappingregistry'] = function () use ($container) {
36
            return new NormalizerObjectMappingRegistry($container['serializer.normalizer.objectmappings']);
37
        };
38 1
39 1
        $container['serializer.normalizer.objectmappings'] = function () {
40
            return [];
41
        };
42 1
43 1
        $container['serializer.encoder'] = function () use ($container) {
44
            return new Encoder($container['serializer.encodertypes']);
45
        };
46 1
47 1
        $container['serializer.encodertypes'] = function () {
48
            $encoderTypes = [];
49
50 1
            $encoderTypes[] = new JsonTypeEncoder();
51 1
            $encoderTypes[] = new JsonxTypeEncoder();
52
            $encoderTypes[] = new UrlEncodedTypeEncoder();
53 1
            $encoderTypes[] = new XmlTypeEncoder();
0 ignored issues
show
Deprecated Code introduced by
The class Chubbyphp\Serialization\Encoder\XmlTypeEncoder has been deprecated: use JsonxTypeEncoder instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

53
            $encoderTypes[] = /** @scrutinizer ignore-deprecated */ new XmlTypeEncoder();
Loading history...
54 1
55 1
            if (class_exists(Yaml::class)) {
56 1
                $encoderTypes[] = new YamlTypeEncoder();
57
            }
58 1
59 1
            @trigger_error(
60
                'Register the encoder types by yourself:'
61
                    .' $container[\'serializer.encodertypes\'] = function () { return [new JsonTypeEncoder()]; };',
62 1
                E_USER_DEPRECATED
63
            );
64 1
65
            return $encoderTypes;
66
        };
67
    }
68
}
69