Completed
Branch master (0e0537)
by Krzysztof
02:41
created

CriteriaCollection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getApplicableCriteria() 0 9 1
A getCriteria() 0 4 1
A addCriteria() 0 4 1
A isItemValid() 0 4 1
1
<?php
2
3
namespace KGzocha\Searcher\Criteria\Collection;
4
5
use KGzocha\Searcher\AbstractCollection;
6
use KGzocha\Searcher\Criteria\CriteriaInterface;
7
8
/**
9
 * @author Krzysztof Gzocha <[email protected]>
10
 * @author Daniel Ribeiro <[email protected]>
11
 */
12
class CriteriaCollection extends AbstractCollection implements CriteriaCollectionInterface
13
{
14
    /**
15
     * @param CriteriaInterface[] $criteria array or \Traversable object
16
     */
17 43
    public function __construct($criteria = [])
18
    {
19 43
        parent::__construct($criteria);
20 23
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 3
    public function getApplicableCriteria()
26
    {
27 3
        return new self(array_filter(
28 3
            $this->getItems(),
29 3
            function (CriteriaInterface $criteria) {
30 3
                return $criteria->shouldBeApplied();
31 3
            }
32
        ));
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 3
    public function getCriteria()
39
    {
40 3
        return $this->getItems();
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 4
    public function addCriteria(CriteriaInterface $criteria)
47
    {
48 4
        return $this->addItem($criteria);
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 15
    protected function isItemValid($item)
55
    {
56 15
        return $item instanceof CriteriaInterface;
57
    }
58
}
59