Completed
Push — master ( 4d9441...c4431a )
by Zoltán
04:15 queued 01:16
created

ArrayFilter::execute()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 11
ccs 8
cts 8
cp 1
rs 9.4285
cc 3
eloc 6
nc 3
nop 2
crap 3
1
<?php namespace BuildR\Collection\Utils;
2
3
/**
4
 * Implementation of PHP array_filter() method. This implmenetation
5
 * imitate ARRAY_FILTER_BOTH flag and works nicely on HHVM, with
6
 * absolutely minimal speed impact.
7
 *
8
 * BuildR PHP Framework
9
 *
10
 * @author Zoltán Borsos <[email protected]>
11
 * @package Collection
12
 * @subpackage Utils
13
 *
14
 * @copyright    Copyright 2015, Zoltán Borsos.
15
 * @license      https://github.com/Zolli/BuildR/blob/master/LICENSE.md
16
 * @link         https://github.com/Zolli/BuildR
17
 */
18
class ArrayFilter {
19
20
    /**
21
     * Execute the filter on the on the given data set. This function
22
     * will preserve array keys.
23
     *
24
     * @param array $data
25
     * @param callable $filter
26
     *
27
     * @return array
28
     */
29 4
    public static function execute($data, callable $filter) {
30 4
        $returnedData = [];
31
32 4
        foreach($data as $key => $value) {
33 4
            if($filter($key, $value) === TRUE) {
34 4
                $returnedData[$key] = $value;
35 4
            }
36 4
        }
37
38 4
        return $returnedData;
39
    }
40
41
}
42