Completed
Push — master ( a69311...5b5097 )
by Christian
02:43
created

ConfigurationCheckPass::process()   B

Complexity

Conditions 8
Paths 4

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 8

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 8.4444
c 0
b 0
f 0
cc 8
nc 4
nop 1
crap 8
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
use Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener;
17
use Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener;
18
19
/**
20
 * Checks if the SensioFrameworkExtraBundle views annotations are disabled when using the View Response listener.
21
 *
22
 * @author Eriksen Costa <[email protected]>
23
 *
24
 * @internal
25
 */
26
final class ConfigurationCheckPass implements CompilerPassInterface
27
{
28 15
    public function process(ContainerBuilder $container): void
29
    {
30 15
        if ($container->has('fos_rest.converter.request_body') && !($container->has('sensio_framework_extra.converter.listener') || $container->has(ParamConverterListener::class))) {
31 1
            throw new \RuntimeException('You need to enable the parameter converter listeners in SensioFrameworkExtraBundle when using the FOSRestBundle RequestBodyParamConverter');
32
        }
33
34 14
        if ($container->has('fos_rest.view_response_listener') && isset($container->getParameter('kernel.bundles')['SensioFrameworkExtraBundle'])) {
35 2
            if (!($container->has('sensio_framework_extra.view.listener') || $container->has(TemplateListener::class))) {
36 1
                throw new \RuntimeException('You must enable the SensioFrameworkExtraBundle view annotations to use the ViewResponseListener. Did you forget to install and enable the TwigBundle?');
37
            }
38
        }
39 13
    }
40
}
41