AbstractRuleListener   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 27.03 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 10
loc 37
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addRule() 0 6 1
A matchRule() 10 10 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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