Completed
Push — master ( d2f8aa...3f97e5 )
by David de
66:53 queued 64:48
created

AnonymousRequestMatcher::__construct()   A

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
/*
4
 * This file is part of the FOSHttpCacheBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\HttpCacheBundle\UserContext;
13
14
use Symfony\Component\HttpFoundation\Request;
15
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
16
17
/**
18
 * Matches anonymous requests using a list of identification headers.
19
 */
20
class AnonymousRequestMatcher implements RequestMatcherInterface
21
{
22
    private $userIdentifierHeaders;
23
24
    /**
25
     * @param array $userIdentifierHeaders List of request headers that authenticate a non-anonymous request
26
     */
27 20
    public function __construct(array $userIdentifierHeaders)
28
    {
29 20
        $this->userIdentifierHeaders = $userIdentifierHeaders;
30 20
    }
31
32 5
    public function matches(Request $request)
33
    {
34 5
        foreach ($this->userIdentifierHeaders as $header) {
35 5
            if ($request->headers->has($header)) {
36 4
                if (strtolower($header) === 'cookie' && 0 === $request->cookies->count()) {
37
                    // ignore empty cookie header
38 2
                    continue;
39
                }
40
41 5
                return false;
42
            }
43
        }
44
45 3
        return true;
46
    }
47
}
48