Completed
Push — master ( 94a152...9d332c )
by Guilh
04:20
created

SerializerConfigurationPass::process()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 6
Metric Value
dl 0
loc 19
ccs 13
cts 13
cp 1
rs 8.8571
cc 6
eloc 11
nc 6
nop 1
crap 6
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\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
17
/**
18
 * Checks if a serializer is either set or can be auto-configured.
19
 *
20
 * @author Christian Flothmann <[email protected]>
21
 * @author Florian Voutzinos <[email protected]>
22
 *
23
 * @internal
24
 */
25
final class SerializerConfigurationPass implements CompilerPassInterface
26
{
27 10
    public function process(ContainerBuilder $container)
28
    {
29 10
        if ($container->has('fos_rest.serializer')) {
30 1
            return;
31
        }
32
33 9
        if (!$container->has('serializer') && !$container->has('jms_serializer.serializer')) {
34 1
            throw new \InvalidArgumentException('Neither a service called "jms_serializer.serializer" nor "serializer" is available and no serializer is explicitly configured. You must either enable the JMSSerializerBundle, enable the FrameworkBundle serializer or configure a custom serializer.');
35
        }
36
37 8
        if ($container->has('jms_serializer.serializer')) {
38 2
            $container->setAlias('fos_rest.serializer', 'jms_serializer.serializer');
39 2
        } else {
40 6
            $container->removeDefinition('fos_rest.serializer.exception_wrapper_serialize_handler');
41
        }
42 8
        if ($container->has('serializer')) {
43 8
            $container->setAlias('fos_rest.serializer', 'serializer');
44 8
        }
45 8
    }
46
}
47