Completed
Push — master ( 839f22...1b3a7e )
by Pavel
04:14
created

NestedCriteriaConfigurator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 32
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A configure() 0 15 4
1
<?php
2
3
namespace ScayTrase\Api\Cruds\Criteria;
4
5
use Doctrine\Common\Collections\Criteria;
6
use ScayTrase\Api\Cruds\CriteriaConfiguratorInterface;
7
use ScayTrase\Api\Cruds\Exception\CriteriaConfigurationException;
8
9
final class NestedCriteriaConfigurator implements CriteriaConfiguratorInterface
10
{
11
    /** @var CriteriaConfiguratorInterface[] */
12
    private $filters = [];
13
14
    /**
15
     * ChainFilter constructor.
16
     *
17
     * @param CriteriaConfiguratorInterface[] $filters
18
     */
19
    public function __construct(array $filters)
20
    {
21
        $this->filters = $filters;
22
    }
23
24
    /** {@inheritdoc} */
25
    public function configure($fqcn, Criteria $criteria, $arguments)
26
    {
27
        if (!is_array($arguments)) {
28
            throw CriteriaConfigurationException::invalidType('array', gettype($arguments));
29
        }
30
31
        $diff = array_keys(array_diff_key($arguments, $this->filters));
32
        if (count($diff) !== 0) {
33
            throw CriteriaConfigurationException::unknown($diff);
34
        }
35
36
        foreach ((array)$arguments as $filter => $item) {
37
            $this->filters[$filter]->configure($fqcn, $criteria, $item);
38
        }
39
    }
40
}
41