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

FilterModelCollection::addFilterModel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 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