Completed
Push — master ( a9d0a0...c83be6 )
by Filipe
07:24
created

QueryFilterCollection::apply()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
/**
4
 * This file is part of slick/mvc package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Mvc\Service\Entity\QueryFilter;
11
12
use Slick\Common\Utils\Collection\AbstractCollection;
13
use Slick\Common\Utils\CollectionInterface;
14
use Slick\Mvc\Service\Entity\QueryFilterCollectionInterface;
15
use Slick\Mvc\Service\Entity\QueryFilterInterface;
16
use Slick\Orm\Repository\QueryObject\QueryObjectInterface;
17
18
/**
19
 * Query Filter Collection
20
 * 
21
 * @package Slick\Mvc\Service\Entity\QueryFilter
22
 * @author  Filipe Silva <[email protected]>
23
 */
24
class QueryFilterCollection extends AbstractCollection implements 
25
    QueryFilterCollectionInterface,
26
    CollectionInterface
27
{
28
29
    /**
30
     * Add a filter to this filter collection
31
     *
32
     * @param QueryFilterInterface $filter
33
     *
34
     * @return $this|self|QueryFilterCollectionInterface
35
     */
36 2
    public function add(QueryFilterInterface $filter)
37
    {
38 2
        $this->data[] = $filter;
39 2
        return $this;
40
    }
41
42
    /**
43
     * Applies the filter to the provided query
44
     *
45
     * @param QueryObjectInterface $query
46
     *
47
     * @return $this|self|QueryFilterCollectionInterface
48
     */
49 4
    public function apply(QueryObjectInterface $query)
50
    {
51
        /** @var QueryFilterInterface $filter */
52 4
        foreach ($this->data as $filter) {
53 2
            $filter->apply($query);
54 2
        }
55 4
        return $this;
56
    }
57
}