SessionSupportCompilerPass   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 22
ccs 5
cts 7
cp 0.7143
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 14 3
1
<?php
2
3
/*
4
 * This file is part of php-cache\cache-bundle package.
5
 *
6
 * (c) 2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Cache\CacheBundle\DependencyInjection\Compiler;
13
14
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
17
/**
18
 * Enable the session support by rewriting the "session.handler" alias.
19
 *
20
 * @author Aaron Scherer <[email protected]>
21
 */
22
class SessionSupportCompilerPass implements CompilerPassInterface
23
{
24
    /**
25
     * @param ContainerBuilder $container
26
     *
27
     * @throws \Exception
28
     */
29 1
    public function process(ContainerBuilder $container)
30
    {
31
        // Check if session support is enabled
32 1
        if (!$container->hasParameter('cache.session')) {
33
            return;
34
        }
35
36
        // If there is no active session support, throw
37 1
        if (!$container->hasAlias('session.storage')) {
38
            throw new \Exception('Session cache support cannot be enabled if there is no session.storage service');
39
        }
40
41 1
        $container->setAlias('session.handler', 'cache.service.session');
42 1
    }
43
}
44