ClosureFilter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A matches() 0 5 2
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 ClosureFilter extends AbstractFilter
17
{
18
    /**
19
     * @var string
20
     */
21
    private $property;
22
23
    /**
24
     * @var callable
25
     */
26
    private $function;
27
28
    /**
29
     * @param string   $property
30
     * @param callable $function ($value) -> bool
31
     */
32 49
    public function __construct($property, callable $function)
33
    {
34 49
        $this->property = $property;
35 49
        $this->function = $function;
36 49
    }
37
38
    /**
39
     * Does this filter match?
40
     *
41
     * @param array $data
42
     *
43
     * @return bool
44
     */
45 48
    public function matches(array $data)
46
    {
47 48
        return (isset($data[$this->property]) &&
48 48
            call_user_func($this->function, $data[$this->property]));
49
    }
50
}
51