Filters   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 64
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A addFilters() 0 6 2
A addFilter() 0 7 2
A apply() 0 12 3
A getFilters() 0 4 1
1
<?php
2
3
namespace SixtyNine\Cloud\Filters;
4
5
class Filters
6
{
7
    /**
8
     * An array of FilterInterface
9
     * @var array
10
     */
11
    protected $filters;
12
13
    /**
14
     * @param FilterInterface[] $filters
15
     */
16 41
    public function __construct(array $filters = array())
17
    {
18 41
        $this->filters = array();
19 41
        $this->addFilters($filters);
20 41
    }
21
22
    /**
23
     * @param FilterInterface[] $filters
24
     */
25 41
    public function addFilters($filters)
26
    {
27 41
        foreach ($filters as $filter) {
28 28
            $this->filters[] = $filter;
29
        }
30 41
    }
31
32
    /**
33
     * Add a filter to filter out words.
34
     * @param FilterInterface $filter
35
     */
36 12
    public function addFilter(FilterInterface $filter)
37
    {
38 12
        if (!in_array($filter, $this->filters)) {
39
40 12
            $this->filters[] = $filter;
41
        }
42 12
    }
43
44
    /**
45
     * @param string $word
46
     * @return bool|string
47
     */
48 34
    public function apply($word)
49
    {
50
        /** @var FilterInterface $filter*/
51 34
        foreach($this->filters as $filter) {
52 34
            if (!$filter->keepWord($word)) {
53 7
                return false;
54
            }
55 29
            $word = $filter->filterWord($word);
56
        }
57
58 29
        return $word;
59
    }
60
61
    /**
62
     * @return array
63
     */
64 6
    public function getFilters()
65
    {
66 6
        return $this->filters;
67
    }
68
}
69