Completed
Push — master ( aa9daf...c0a8a5 )
by David
10:44
created

src/EventListener/AbstractRuleListener.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 33
    public function addRule(
32
        RequestMatcherInterface $requestMatcher,
33
        array $settings = []
34
    ) {
35 33
        $this->rulesMap[] = [$requestMatcher, $settings];
36 33
    }
37
38
    /**
39
     * Return the settings for the current request if any rule matches.
40
     *
41
     * @param Request $request
42
     *
43
     * @return array|false Settings to apply or false if no rule matched
44
     */
45 28 View Code Duplication
    protected function matchRule(Request $request)
0 ignored issues
show
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...
46
    {
47 28
        foreach ($this->rulesMap as $elements) {
48 23
            if ($elements[0]->matches($request)) {
49 9
                return $elements[1];
50
            }
51
        }
52
53 24
        return false;
54
    }
55
}
56