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

Resolver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 41
rs 10
c 0
b 0
f 0

2 Methods

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