Completed
Push — master ( 957717...7a0390 )
by Christian
02:31 queued 11s
created

JMSHandlersPass::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 6
cts 8
cp 0.75
rs 9.8333
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.0625
1
<?php
2
3
/*
4
 * This file is part of the FOSRestBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\RestBundle\DependencyInjection\Compiler;
13
14
use Symfony\Component\DependencyInjection\Alias;
15
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
18
/**
19
 * Checks if the JMS serializer is available to be able to use handlers.
20
 *
21
 * @author Christian Flothmann <[email protected]>
22
 *
23
 * @internal
24
 */
25
final class JMSHandlersPass implements CompilerPassInterface
26
{
27 5
    public function process(ContainerBuilder $container): void
28
    {
29 5
        if ($container->has('jms_serializer.handler_registry')) {
30
            // the public alias prevents the handler registry definition from being removed
31
            $container->setAlias('fos_rest.serializer.jms_handler_registry', new Alias('jms_serializer.handler_registry', true));
32
33
            return;
34
        }
35
36 5
        $container->removeDefinition('fos_rest.serializer.handler_registry');
37 5
        $container->removeDefinition('fos_rest.serializer.exception_normalizer.jms');
38 5
        $container->getParameterBag()->remove('jms_serializer.form_error_handler.class');
39 5
    }
40
}
41