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

BodyMatchingPolicy   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A match() 0 12 3
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 BodyMatchingPolicy implements MatchingPolicy
10
{
11
    /**
12
     * @var \Coduo\PHPMatcher\Matcher
13
     */
14
    private $phpMatcher;
15
16
    /**
17
     * @param Matcher $phpMatcher
18
     */
19
    public function __construct(Matcher $phpMatcher)
20
    {
21
        $this->phpMatcher = $phpMatcher;
22
    }
23
24
    /**
25
     * @param Request $request
26
     * @param Element $config
27
     * @return boolean
28
     */
29
    public function match(Request $request, Element $config)
30
    {
31
        if (!$config->getRequest()->hasBody()) {
32
            return true;
33
        }
34
35
        if (!$this->phpMatcher->match($request->getContent(), $config->getRequest()->getBody())) {
36
            return false;
37
        }
38
39
        return true;
40
    }
41
}
42