Completed
Push — master ( c5de01...c9c19d )
by
unknown
07:34 queued 05:10
created

HeadersMatchingPolicy   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 25 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 9
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B match() 9 18 5

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
namespace Coduo\TuTu\Request;
4
5
use Coduo\PHPMatcher\Matcher;
6
use Coduo\TuTu\Config\Element;
7
use Symfony\Component\HttpFoundation\Request;
8
9
class HeadersMatchingPolicy implements MatchingPolicy
10
{
11
    /**
12
     * @var \Coduo\PHPMatcher\Matcher\Matcher
13
     */
14
    private $phpMatcher;
15
16
    public function __construct(Matcher $phpMatcher)
17
    {
18
        $this->phpMatcher = $phpMatcher;
0 ignored issues
show
Documentation Bug introduced by
It seems like $phpMatcher of type object<Coduo\PHPMatcher\Matcher> is incompatible with the declared type object<Coduo\PHPMatcher\Matcher\Matcher> of property $phpMatcher.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
19
    }
20
21
    /**
22
     * @param Request $request
23
     * @param Element $config
24
     * @return boolean
25
     */
26
    public function match(Request $request, Element $config)
27
    {
28
        if (!$config->getRequest()->hasHeaders()) {
29
            return true;
30
        }
31
32 View Code Duplication
        foreach ($config->getRequest()->getHeaders() as $headerName => $headerValuePattern) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
33
            if (!$request->headers->has($headerName)) {
34
                return false;
35
            }
36
37
            if (!$this->phpMatcher->match($request->headers->get($headerName), $headerValuePattern)) {
38
                return false;
39
            }
40
        }
41
42
        return true;
43
    }
44
}
45