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

BodyMatchingPolicy::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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