Completed
Pull Request — master (#34)
by Krzysztof
02:14
created

FilterModelCollection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A getImposedModels() 0 9 1
A getFilterModels() 0 4 1
A addFilterModel() 0 6 1
1
<?php
2
3
namespace KGzocha\Searcher\FilterModel\Collection;
4
5
use KGzocha\Searcher\FilterModel\FilterModelInterface;
6
7
class FilterModelCollection implements FilterModelCollectionInterface
8
{
9
    /**
10
     * @var FilterModelInterface[]
11
     */
12
    protected $filterModels;
13
14
    /**
15
     * @param FilterModelInterface[] $filterModels
16
     */
17 7
    public function __construct(array $filterModels = [])
18
    {
19 7
        $this->filterModels = [];
20 7
        foreach ($filterModels as $filterModel) {
21
            // In this way we will ensure that
22
            // every element in array has correct type
23 5
            $this->addFilterModel($filterModel);
24 7
        }
25 7
    }
26
27
    /**
28
     * @inheritdoc
29
     */
30 3
    public function getImposedModels()
31
    {
32 3
        return array_filter(
33 3
            $this->getFilterModels(),
34 3
            function(FilterModelInterface $filterModel) {
35 3
                return $filterModel->isImposed();
36
            }
37 3
        );
38
    }
39
40
    /**
41
     * {@inheritDoc}
42
     */
43 6
    public function getFilterModels()
44
    {
45 6
        return $this->filterModels;
46
    }
47
48
    /**
49
     * {@inheritDoc}
50
     */
51 5
    public function addFilterModel(FilterModelInterface $filterModel)
52
    {
53 5
        $this->filterModels[] = $filterModel;
54
55 5
        return $this;
56
    }
57
}
58