AbstractRuleListener::addRule()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 2
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\EventListener;
13
14
use Symfony\Component\HttpFoundation\Request;
15
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
16
17
abstract class AbstractRuleListener
18
{
19
    /**
20
     * @var array List of arrays with RequestMatcherInterface, settings array
21
     */
22
    private $rulesMap = [];
23
24
    /**
25
     * Add a rule matcher with a list of header directives to apply if the
26
     * request and response are matched.
27
     *
28
     * @param RequestMatcherInterface $requestMatcher The headers apply to responses matched by this matcher
29
     * @param array                   $settings       An array of header configuration
30
     */
31 35
    public function addRule(
32
        RequestMatcherInterface $requestMatcher,
33
        array $settings = []
34
    ) {
35 35
        $this->rulesMap[] = [$requestMatcher, $settings];
36 35
    }
37
38
    /**
39
     * Return the settings for the current request if any rule matches.
40
     *
41
     * @return array|false Settings to apply or false if no rule matched
42
     */
43 View Code Duplication
    protected function matchRule(Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
    {
45 28
        foreach ($this->rulesMap as $elements) {
46
            if ($elements[0]->matches($request)) {
47 28
                return $elements[1];
48 23
            }
49 9
        }
50
51
        return false;
52
    }
53
}
54