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

ChainMatchingPolicy   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A match() 0 14 4
A addMatchingPolicy() 0 4 1
1
<?php
2
3
namespace Coduo\TuTu\Request;
4
5
use Coduo\TuTu\Config\Element;
6
use Symfony\Component\HttpFoundation\Request;
7
8
class ChainMatchingPolicy implements MatchingPolicy
9
{
10
    /**
11
     * @var array|MatchingPolicy[]
12
     */
13
    private $matchingPolicies;
14
15
    public function __construct()
16
    {
17
        $this->matchingPolicies = [];
18
    }
19
20
    /**
21
     * @param Request $request
22
     * @param Element $config
23
     * @return bool
24
     */
25
    public function match(Request $request, Element $config)
26
    {
27
        if (!count($this->matchingPolicies)) {
28
            return false;
29
        }
30
31
        foreach ($this->matchingPolicies as $matchingPolicy) {
32
            if (!$matchingPolicy->match($request, $config)) {
33
                return false;
34
            }
35
        }
36
37
        return true;
38
    }
39
40
    /**
41
     * @param MatchingPolicy $matchingPolicy
42
     */
43
    public function addMatchingPolicy(MatchingPolicy $matchingPolicy)
44
    {
45
        $this->matchingPolicies[] = $matchingPolicy;
46
    }
47
}
48