SymfonySecurityExtension   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 0
loc 42
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A loadConfiguration() 0 7 1
A beforeCompile() 0 10 2
A loadAccessDecisionManagerFactoryWithVoters() 0 4 1
A loadFirewallMap() 0 5 1
A loadMediator() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Symplify.
7
 * Copyright (c) 2014 Tomas Votruba (http://tomasvotruba.cz)
8
 */
9
10
namespace Symplify\SymfonySecurity\Adapter\Nette\DI;
11
12
use Nette\DI\Compiler;
13
use Nette\DI\CompilerExtension;
14
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
15
use Symplify\SymfonySecurity\Contract\Http\FirewallHandlerInterface;
16
use Symplify\SymfonySecurity\Contract\Http\FirewallMapFactoryInterface;
17
use Symplify\SymfonySecurity\Contract\HttpFoundation\RequestMatcherInterface;
18
use Symplify\SymfonySecurity\Core\Authorization\AccessDecisionManagerFactory;
19
20
final class SymfonySecurityExtension extends CompilerExtension
21
{
22 4
    public function loadConfiguration()
23
    {
24 4
        Compiler::loadDefinitions(
25 4
            $this->getContainerBuilder(),
26 4
            $this->loadFromFile(__DIR__ . '/../config/services.neon')['services']
27
        );
28 4
    }
29
30 3
    public function beforeCompile()
31
    {
32 3
        $containerBuilder = $this->getContainerBuilder();
33
34 3
        $this->loadAccessDecisionManagerFactoryWithVoters();
35
36 3
        if ($containerBuilder->findByType(FirewallHandlerInterface::class)) {
37 2
            $this->loadFirewallMap();
38
        }
39 3
    }
40
41 3
    private function loadAccessDecisionManagerFactoryWithVoters()
42
    {
43 3
        $this->loadMediator(AccessDecisionManagerFactory::class, VoterInterface::class, 'addVoter');
44 3
    }
45
46 2
    private function loadFirewallMap()
47
    {
48 2
        $this->loadMediator(FirewallMapFactoryInterface::class, FirewallHandlerInterface::class, 'addFirewallHandler');
49 2
        $this->loadMediator(FirewallMapFactoryInterface::class, RequestMatcherInterface::class, 'addRequestMatcher');
50 2
    }
51
52 3
    private function loadMediator(string $mediatorClass, string $colleagueClass, string $adderMethod)
53
    {
54 3
        $containerBuilder = $this->getContainerBuilder();
55
56 3
        $mediatorDefinition = $containerBuilder->getDefinition($containerBuilder->getByType($mediatorClass));
57 3
        foreach ($containerBuilder->findByType($colleagueClass) as $colleagueDefinition) {
58 3
            $mediatorDefinition->addSetup($adderMethod, ['@' . $colleagueDefinition->getClass()]);
59
        }
60 3
    }
61
}
62