Completed
Pull Request — master (#14)
by Pavel
10:37 queued 02:14
created

JmsSerializerCompilerPass::process()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 29
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 5.1727

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 29
ccs 17
cts 21
cp 0.8095
rs 8.439
c 1
b 0
f 0
cc 5
eloc 17
nc 9
nop 1
crap 5.1727
1
<?php
2
3
namespace ScayTrase\Api\Cruds\DependencyInjection\Compiler;
4
5
use ScayTrase\Api\Cruds\Adaptors\JmsSerializer\JmsValidatorSubscriber;
6
use Symfony\Component\Config\FileLocator;
7
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Loader;
10
use Symfony\Component\DependencyInjection\Reference;
11
12
final class JmsSerializerCompilerPass implements CompilerPassInterface
13
{
14
    /** {@inheritdoc} */
15 17
    public function process(ContainerBuilder $container)
16
    {
17 17
        if (!$container->has('jms_serializer')) {
18 9
            return;
19
        }
20
21 8
        if (!$container->has('debug.stopwatch')) {
22
            $container->removeDefinition('jms_serializer.stopwatch_subscriber');
23
        }
24
25 8
        if (!$container->has('translator')) {
26
            $container->removeDefinition('jms_serializer.form_error_handler');
27
        }
28
29 8
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../../Resources/config'));
30 8
        $loader->load('jms_serializer.yml');
31
32 8
        if ($container->has('validator')) {
33 8
            $definition = $container->register('cruds.api.jms_serializer.validator', JmsValidatorSubscriber::class);
34 8
            $definition->setArguments([new Reference('validator')]);
35 8
            $definition->addTag('jms_serializer.event_subscriber');
36 8
        }
37
38 8
        $normalizer = $container->getDefinition('cruds.api.listener.response_normalizer');
39 8
        $normalizer->replaceArgument(0, new Reference('cruds.jms_serializer'));
40
41 8
        $serializer = $container->getDefinition('cruds.api.listener.response_serializer');
42 8
        $serializer->replaceArgument(0, new Reference('cruds.jms_serializer'));
43 8
    }
44
}
45