FirewallMap::add()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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