FirewallMap   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 26
ccs 7
cts 8
cp 0.875
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 7 1
A getListeners() 0 10 4
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 Nette\Http\IRequest;
13
use Symfony\Component\Security\Http\Firewall\ExceptionListener;
14
use Symplify\SymfonySecurity\Contract\Http\FirewallMapInterface;
15
use Symplify\SymfonySecurity\Contract\HttpFoundation\RequestMatcherInterface;
16
17
/**
18
 * Mimics @see \Symfony\Component\Security\Http\FirewallMap.
19
 */
20
final class FirewallMap implements FirewallMapInterface
21
{
22
    /**
23
     * @var array|RequestMatcherInterface[][]
24
     */
25
    private $map = [];
26
27 2
    public function add(
28
        RequestMatcherInterface $requestMatcher = null,
29
        array $listeners = [],
30
        ExceptionListener $exceptionListener = null
31
    ) {
32 2
        $this->map[] = [$requestMatcher, $listeners, $exceptionListener];
33 2
    }
34
35 1
    public function getListeners(IRequest $request) : array
36
    {
37 1
        foreach ($this->map as $elements) {
38 1
            if ($elements[0] === null || $elements[0]->matches($request)) {
39 1
                return [$elements[1], $elements[2]];
40
            }
41
        }
42
43
        return [[], null];
44
    }
45
}
46