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

SerializerConfigurationPass   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 22
ccs 13
cts 13
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 19 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