Completed
Push — master ( f78604...98e267 )
by Pavel
04:30
created

SymfonySerializerCompilerPass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 78.56%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 5
c 4
b 0
f 0
lcom 0
cbo 4
dl 0
loc 30
ccs 11
cts 14
cp 0.7856
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 26 5
1
<?php
2
3
namespace ScayTrase\Api\Cruds\DependencyInjection\Compiler;
4
5
use Symfony\Component\Config\FileLocator;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Loader;
9
use Symfony\Component\DependencyInjection\Reference;
10
use Symfony\Component\Serializer\SerializerInterface;
11
12
final class SymfonySerializerCompilerPass implements CompilerPassInterface
13
{
14
    /** {@inheritdoc} */
15 2
    public function process(ContainerBuilder $container)
16
    {
17 2
        if (!$container->has('serializer') || $container->hasAlias('serializer')) {
18
19 1
            return;
20
        }
21
22 1
        $class = $container->getDefinition('serializer')->getClass();
23
24 1
        if ('%serializer.class%' === $class) {
25
            // 2.x Definition
26
            $class = $container->getParameter($class);
27
        }
28
29 1
        if (!in_array(SerializerInterface::class, class_implements($class), true)) {
30
            return;
31
        }
32
33 1
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../../Resources/config'));
34 1
        $loader->load('symfony_serializer.yml');
35
36
        /** @var Reference $converter */
37 1
        $converter = $container->getDefinition('serializer.normalizer.object')->getArgument(1);
38
39 1
        $container->setAlias('serializer.normalizer.object.name_converter', (string)$converter);
40 1
    }
41
}
42