Completed
Pull Request — master (#46)
by Daniel
03:48
created

QueryCriteriaCollection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
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 52
ccs 16
cts 16
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A getApplicableCriteria() 0 9 1
A getCriteria() 0 4 1
A addQueryCriteria() 0 6 1
1
<?php
2
3
namespace KGzocha\Searcher\QueryCriteria\Collection;
4
5
use KGzocha\Searcher\QueryCriteria\QueryCriteriaInterface;
6
7
/**
8
 * Class QueryCriteriaCollection
9
 *
10
 * @author Daniel Ribeiro <[email protected]>
11
 * @package KGzocha\Searcher\QueryCriteria\Collection
12
 */
13
class QueryCriteriaCollection implements QueryCriteriaCollectionInterface
14
{
15
    /**
16
     * @var QueryCriteriaInterface[]
17
     */
18
    protected $queryCriteria;
19
20
    /**
21
     * @param QueryCriteriaInterface[] $providedCriteria
22
     */
23 8
    public function __construct(array $providedCriteria = [])
24
    {
25 8
        $this->queryCriteria = [];
26
27 8
        foreach ($providedCriteria as $criteria) {
28
            // In this way we will ensure that
29
            // every element in array has correct type
30 5
            $this->addQueryCriteria($criteria);
31
        }
32 8
    }
33
34
    /**
35
     * @inheritdoc
36
     */
37 2
    public function getApplicableCriteria()
38
    {
39 2
        return array_filter(
40 2
            $this->getCriteria(),
41 2
            function(QueryCriteriaInterface $queryCriteria) {
42 2
                return $queryCriteria->shouldBeApplied();
43 2
            }
44
        );
45
    }
46
47
    /**
48
     * {@inheritDoc}
49
     */
50 6
    public function getCriteria()
51
    {
52 6
        return $this->queryCriteria;
53
    }
54
55
    /**
56
     * {@inheritDoc}
57
     */
58 5
    public function addQueryCriteria(QueryCriteriaInterface $queryCriteria)
59
    {
60 5
        $this->queryCriteria[] = $queryCriteria;
61
62 5
        return $this;
63
    }
64
}
65