OneOfFilter   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
c 2
b 0
f 1
lcom 1
cbo 1
dl 0
loc 43
ccs 14
cts 14
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A addFilter() 0 4 1
A matches() 0 10 3
1
<?php
2
/**
3
 * This file is part of graze/array-filter
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/array-filter/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/array-filter
12
 */
13
14
namespace Graze\ArrayFilter;
15
16
class OneOfFilter extends AbstractFilter
17
{
18
    /**
19
     * @var callable[]
20
     */
21
    private $filters;
22
23
    /**
24
     * @param array $filters
25
     */
26 7
    public function __construct(array $filters = [])
27
    {
28 7
        foreach ($filters as $filter) {
29 5
            $this->addFilter($filter);
30 7
        }
31 7
    }
32
33
    /**
34
     * @param callable $filter
35
     */
36 6
    public function addFilter(callable $filter)
37
    {
38 6
        $this->filters[] = $filter;
39 6
    }
40
41
    /**
42
     * Loop through all the filters and only return if all match
43
     *
44
     * @param array $data
45
     *
46
     * @return bool
47
     */
48 6
    public function matches(array $data)
49
    {
50 6
        foreach ($this->filters as $filter) {
51 6
            if ($filter($data)) {
52 6
                return true;
53
            }
54 6
        }
55
56 6
        return false;
57
    }
58
}
59