Completed
Push — master-4.0 ( 71618b...2eaeb5 )
by Krzysztof
03:06 queued 03:01
created

CriteriaCollection::count()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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