Completed
Pull Request — master (#319)
by David
06:22
created

SecurityContextPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 57.14%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 19
ccs 4
cts 7
cp 0.5714
rs 10
c 2
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 11 4
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 Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Reference;
17
18
/**
19
 * In Symfony < 2.6, replace the new security.token_storage service with the
20
 * deprecated security.context service.
21
 */
22
class SecurityContextPass implements CompilerPassInterface
23
{
24
    const ROLE_PROVIDER_SERVICE = 'fos_http_cache.user_context.role_provider';
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 1
    public function process(ContainerBuilder $container)
30
    {
31 1
        if (!$container->has(self::ROLE_PROVIDER_SERVICE)) {
32
            return;
33
        }
34
35 1
        if (!$container->has('security.token_storage') && $container->has('security.context')) {
36
            $definition = $container->getDefinition(self::ROLE_PROVIDER_SERVICE);
37
            $definition->replaceArgument(0, new Reference('security.context'));
38
        }
39 1
    }
40
}
41