FirewallMap::getListeners()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 4.128

Importance

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