TagListenerPass   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 25
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 13 3
A hasControllerListener() 0 5 2
1
<?php
2
3
/*
4
 * This file is part of the FOSHttpCacheBundle 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\HttpCacheBundle\DependencyInjection\Compiler;
13
14
use Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener;
15
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
18
/**
19
 * Check for required ControllerListener if TagListener is enabled.
20
 */
21
class TagListenerPass implements CompilerPassInterface
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26 3
    public function process(ContainerBuilder $container)
27
    {
28 3
        if (true === $container->getParameter('fos_http_cache.compiler_pass.tag_annotations')
29 3
            && !$this->hasControllerListener($container)
30
        ) {
31 1
            throw new \RuntimeException(
32
                'Tag annotations are enabled by default because otherwise things could silently not work.'
33
                .' The annotations require the SensioFrameworkExtraBundle ControllerListener. If you do not use'
34
                .' annotations for tags, set "fos_http_cache.tags.annotations.enabled: false". Otherwise install'
35 1
                .' sensio/framework-extra-bundle and enabled it in your kernel.'
36
            );
37
        }
38 2
    }
39
40 3
    private function hasControllerListener(ContainerBuilder $container)
41
    {
42 3
        return $container->has('sensio_framework_extra.controller.listener') ||
43 3
            $container->has(ControllerListener::class);
44
    }
45
}
46