Completed
Push — master ( 2e0cd6...c623e8 )
by Pavel
12:31
created

SymfonySerializerCompilerPass::process()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 19
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5.675

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 19
ccs 7
cts 10
cp 0.7
rs 8.8571
cc 5
eloc 8
nc 5
nop 1
crap 5.675
1
<?php
2
3
namespace ScayTrase\Api\Cruds\DependencyInjection\Compiler;
4
5
use ScayTrase\Api\Cruds\Adaptors\DoctrineOrm\CircularReferenceHandler;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Definition;
9
use Symfony\Component\DependencyInjection\DefinitionDecorator;
10
use Symfony\Component\DependencyInjection\Reference;
11
use Symfony\Component\Serializer\SerializerInterface;
12
13
final class SymfonySerializerCompilerPass implements CompilerPassInterface
14
{
15
    /** {@inheritdoc} */
16 2
    public function process(ContainerBuilder $container)
17
    {
18 2
        if (!$container->has('serializer') || $container->hasAlias('serializer')) {
19
20 1
            return;
21
        }
22
23 1
        $class = $container->getDefinition('serializer')->getClass();
24
25 1
        if ('%serializer.class%' === $class) {
26
            // 2.x Definition
27
            $class = $container->getParameter($class);
28
        }
29
30 1
        if (!in_array(SerializerInterface::class, class_implements($class), true)) {
31
32
            return;
33
        }
34 1
    }
35
}
36