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

CriteriaBuilderCollection::checkType()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 12
loc 12
rs 9.2
ccs 7
cts 7
cp 1
cc 4
eloc 7
nc 2
nop 1
crap 4
1
<?php
2
3
namespace KGzocha\Searcher\CriteriaBuilder\Collection;
4
5
use KGzocha\Searcher\AbstractCollection;
6
use KGzocha\Searcher\Context\SearchingContextInterface;
7
use KGzocha\Searcher\CriteriaBuilder\CriteriaBuilderInterface;
8
9
/**
10
 * @author Krzysztof Gzocha <[email protected]>
11
 */
12
class CriteriaBuilderCollection extends AbstractCollection implements CriteriaBuilderCollectionInterface
13
{
14
    /**
15
     * @param CriteriaBuilderInterface[] $builders array or \Traversable object
16
     */
17 9
    public function __construct($builders = [])
18
    {
19 9
        parent::__construct($builders);
20 4
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 1
    public function addCriteriaBuilder(CriteriaBuilderInterface $criteriaBuilder)
26
    {
27 1
        return $this->addItem($criteriaBuilder);
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 1
    public function getCriteriaBuilders()
34
    {
35 1
        return $this->getItems();
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 2
    public function getCriteriaBuildersForContext(
42
        SearchingContextInterface $searchingContext
43
    ) {
44 2
        return new self(array_filter(
45 2
            $this->getItems(),
46 2
            function (CriteriaBuilderInterface $criteriaBuilder) use ($searchingContext) {
47 2
                return $criteriaBuilder->supportsSearchingContext($searchingContext);
48 2
            }
49
        ));
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 3
    protected function isItemValid($item)
56
    {
57 3
        return $item instanceof CriteriaBuilderInterface;
58
    }
59
}
60