FirewallMapFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addRequestMatcher() 0 4 1
A addFirewallHandler() 0 4 1
A create() 0 11 3
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\Http;
11
12
use Symplify\SymfonySecurity\Contract\Http\FirewallHandlerInterface;
13
use Symplify\SymfonySecurity\Contract\Http\FirewallMapFactoryInterface;
14
use Symplify\SymfonySecurity\Contract\Http\FirewallMapInterface;
15
use Symplify\SymfonySecurity\Contract\HttpFoundation\RequestMatcherInterface;
16
17
final class FirewallMapFactory implements FirewallMapFactoryInterface
18
{
19
    /**
20
     * @var RequestMatcherInterface[]
21
     */
22
    private $requestMatchers = [];
23
24
    /**
25
     * @var FirewallHandlerInterface[][]
26
     */
27
    private $firewallHandlers = [];
28
29 2
    public function addRequestMatcher(RequestMatcherInterface $requestMatcher)
30
    {
31 2
        $this->requestMatchers[$requestMatcher->getFirewallName()] = $requestMatcher;
32 2
    }
33
34 2
    public function addFirewallHandler(FirewallHandlerInterface $firewallHandler)
35
    {
36 2
        $this->firewallHandlers[$firewallHandler->getFirewallName()][] = $firewallHandler;
37 2
    }
38
39 2
    public function create() : FirewallMapInterface
40
    {
41 2
        $firewallMap = new FirewallMap();
42 2
        foreach ($this->requestMatchers as $firewallName => $requestMatcher) {
43 2
            if (isset($this->firewallHandlers[$firewallName])) {
44 2
                $firewallMap->add($requestMatcher, $this->firewallHandlers[$firewallName]);
45
            }
46
        }
47
48 2
        return $firewallMap;
49
    }
50
}
51