Completed
Push — master ( 49cea0...b2ab19 )
by Harry
02:41
created

ClosureFilter::matches()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
3
namespace Graze\ArrayFilter;
4
5
use Closure;
6
7
class ClosureFilter extends AbstractFilter
8
{
9
    /**
10
     * @var string
11
     */
12
    private $property;
13
14
    /**
15
     * @var Closure
16
     */
17
    private $function;
18
19
    /**
20
     * @param string  $property
21
     * @param Closure $function ($value) -> bool
22
     */
23
    public function __construct($property, Closure $function)
24
    {
25
        $this->property = $property;
26
        $this->function = $function;
27
    }
28
29
    /**
30
     * Does this filter match?
31
     *
32
     * @param array $data
33
     *
34
     * @return bool
35
     */
36
    public function matches(array $data)
37
    {
38
        return (isset($data[$this->property]) &&
39
            call_user_func($this->function, $data[$this->property]));
40
    }
41
}
42