Passed
Push — master ( d2ad69...686350 )
by Kacper
02:44
created

ArrayHelper::filterByKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 2
1
<?php
2
/**
3
 * Highlighter
4
 *1
5
 * Copyright (C) 2015, Some right reserved.
6
 *
7
 * @author Kacper "Kadet" Donat <[email protected]>
8
 *
9
 * Contact with author:
10
 * Xmpp: [email protected]
11
 * E-mail: [email protected]
12
 *
13
 * From Kadet with love.
14
 */
15
16
namespace Kadet\Highlighter\Utils;
17
18
19
class ArrayHelper
20
{
21 1
    public static function rearrange(array $array, array $keys)
22
    {
23
        return array_combine($keys, array_map(function ($key) use ($array) {
24 1
            return $array[$key];
25 1
        }, $keys));
26
    }
27
28
    public static function column(array $array, $index)
29
    {
30
        return array_map(function ($e) use ($index) { return $e[$index]; }, $array);
31
    }
32
33 1
    public static function find(array $array, callable $tester)
34
    {
35 1
        foreach ($array as $key => $value) {
36 1
            if ($tester($key, $value)) {
37 1
                return $key;
38
            }
39 1
        }
40
41 1
        return false;
42
    }
43
}