Completed
Pull Request — master (#46)
by
unknown
05:21
created

ParameterMatchingPolicy::match()   D

Complexity

Conditions 9
Paths 11

Size

Total Lines 27
Code Lines 14

Duplication

Lines 17
Ratio 62.96 %

Importance

Changes 0
Metric Value
dl 17
loc 27
rs 4.909
c 0
b 0
f 0
cc 9
eloc 14
nc 11
nop 2
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 ParameterMatchingPolicy implements MatchingPolicy
10
{
11
    /**
12
     * @var \Coduo\PHPMatcher\Matcher
13
     */
14
    private $phpMatcher;
15
16
    public function __construct(Matcher $phpMatcher)
17
    {
18
        $this->phpMatcher = $phpMatcher;
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()->hasBodyParameters() && !$config->getRequest()->hasQueryParameters()) {
29
            return true;
30
        }
31
32 View Code Duplication
        foreach ($config->getRequest()->getQueryParameters() as $name => $valuePattern) {
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->query->has($name)) {
34
                return false;
35
            }
36
            if (!$this->phpMatcher->match($request->query->get($name), $valuePattern)) {
37
                return false;
38
            }
39
        }
40
41 View Code Duplication
        foreach ($config->getRequest()->getBodyParameters() as $name => $valuePattern) {
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...
42
            if (!$request->request->has($name)) {
43
                return false;
44
            }
45
46
            if (!$this->phpMatcher->match($request->request->get($name), $valuePattern)) {
47
                return false;
48
            }
49
        }
50
51
        return true;
52
    }
53
}
54