SecurityMiddlewarePass::process()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
namespace League\Tactician\Bundle\DependencyInjection\Compiler;
3
4
use League\Tactician\Bundle\Middleware\SecurityMiddleware;
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Definition;
8
use Symfony\Component\DependencyInjection\Reference;
9
10
/**
11
 * This compiler pass registers security middleware if possible
12
 */
13
class SecurityMiddlewarePass implements CompilerPassInterface
14
{
15
    const SERVICE_ID = 'tactician.middleware.security';
16
17
    /**
18
     * {@inheritdoc}
19
     */
20 66
    public function process(ContainerBuilder $container)
21
    {
22 66
        if (false === $container->hasDefinition('security.authorization_checker')) {
23 48
            return;
24
        }
25
26 18
        $container->setDefinition(
27 18
            static::SERVICE_ID,
28 18
            new Definition(SecurityMiddleware::class, [ new Reference('security.authorization_checker') ])
29
        );
30 18
    }
31
}
32
33