Completed
Push — master ( cdeb45...018697 )
by David
12:24
created

QuerystringRequestMatcher   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 31
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setQueryString() 0 4 1
A matches() 0 12 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 21
    public function matches(Request $request)
39
    {
40 21
        if (!parent::matches($request)) {
41 16
            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