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

ArrayHelper::rearrange()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
crap 1
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
}