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

ClosureFilter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 35
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A matches() 0 5 2
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