FirewallMapFactory::addFirewallHandler()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
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