FilterChain   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 41
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 5 1
A filter() 0 9 2
1
<?php
2
3
/**
4
 * This file is part of slick/filter 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\Filter;
11
12
/**
13
 * Filter Chain
14
 *
15
 * @package Slick\Filter
16
 * @author  Filipe Silva <[email protected]>
17
 */
18
class FilterChain implements FilterChainInterface
19
{
20
21
    /**
22
     * @var FilterInterface[]
23
     */
24
    protected $filters = [];
25
26
    /**
27
     * Add a filter to the chain
28
     *
29
     * @param FilterInterface $filter
30
     *
31
     * @return self|$this|FilterChainInterface
32
     */
33 2
    public function add(FilterInterface $filter)
34
    {
35 2
        array_push($this->filters, $filter);
36 2
        return $this;
37
    }
38
39
    /**
40
     * Returns the result of filtering $value
41
     *
42
     * @param mixed $value
43
     *
44
     * @throws Exception\CannotFilterValueException
45
     *      If filtering $value is impossible.
46
     *
47
     * @return mixed
48
     */
49 2
    public function filter($value)
50
    {
51 2
        $result = $value;
52 2
        foreach ($this->filters as $filter) {
53 2
            $result = $filter->filter($value);
54 2
            $value = $result;
55 2
        }
56 2
        return $result;
57
    }
58
}
59