UriPatterns::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
namespace Dkplus\CsrfApiUnprotectionBundle\UnprotectionRule;
3
4
use Assert\Assertion;
5
use Symfony\Component\HttpFoundation\Request;
6
7
final class UriPatterns implements UnprotectionRule
8
{
9
    /** @var string[] */
10
    private $patterns;
11
12 6
    public function __construct(array $patterns)
13
    {
14 6
        foreach ($patterns as $each) {
15 5
            Assertion::string($each);
16
        }
17 6
        $this->patterns = $patterns;
18 6
    }
19
20 5
    public function matches(Request $request)
21
    {
22 5
        foreach ($this->patterns as $each) {
23 5
            if (preg_match($each, $request->getRequestUri())) {
24 5
                return true;
25
            }
26
        }
27 2
        return false;
28
    }
29
}
30