QuerystringRequestMatcher::matches()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
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\Http\RequestMatcher;
13
14
use Symfony\Component\HttpFoundation\Request;
15
use Symfony\Component\HttpFoundation\RequestMatcher as SymfonyRequestMatcher;
16
17
/**
18
 * Extend the Symfony RequestMatcher class to support query string matching.
19
 */
20
class QuerystringRequestMatcher extends SymfonyRequestMatcher
21
{
22
    /**
23
     * @var string Regular expression to match the query string part of the request url
24
     */
25
    private $queryString;
26
27
    /**
28
     * @param string $queryString
29
     */
30 2
    public function setQueryString($queryString)
31
    {
32 2
        $this->queryString = $queryString;
33 2
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 25
    public function matches(Request $request)
39
    {
40 25
        if (!parent::matches($request)) {
41 20
            return false;
42
        }
43
44 9
        if (null === $this->queryString) {
45 7
            return true;
46
        }
47
48 2
        return (bool) preg_match('{'.$this->queryString.'}', rawurldecode($request->getQueryString()));
49
    }
50
}
51