Completed
Push — master ( 676347...810a64 )
by Artem
02:44
created

ArrayHelper::replaceValuesByMatchingKeys()   A

Complexity

Conditions 6
Paths 5

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 6

Importance

Changes 0
Metric Value
cc 6
eloc 9
nc 5
nop 3
dl 0
loc 16
rs 9.2222
c 0
b 0
f 0
ccs 10
cts 10
cp 1
crap 6
1
<?php
2
3
namespace Slides\Connector\Auth\Helpers;
4
5
/**
6
 * Class ArrayHelper
7
 *
8
 * @package Slides\Connector\Auth\Helpers
9
 */
10
class ArrayHelper
11
{
12
    /**
13
     * Replace values that matches with the given keys.
14
     *
15
     * @param array $input Replacing array
16
     * @param array $keys
17
     * @param \Closure|string $replacement Handling callback
18
     *
19
     * @return array
20
     */
21 10
    public static function replaceValuesByMatchingKeys(array $input, array $keys, $replacement)
22
    {
23 10
        $keys = array_map('strtolower', $keys);
24
25 10
        foreach ($input as $key => $value) {
26 10
            if(is_array($value)) {
27 2
                $input[$key] = static::replaceValuesByMatchingKeys($value, $keys, $replacement);
28
            }
29 10
            elseif(is_string($key) && in_array(strtolower($key), $keys)) {
30 7
                $input[$key] = $replacement instanceof \Closure
31 1
                    ? $replacement($key, $value)
32 10
                    : $replacement;
33
            }
34
        }
35
36 10
        return $input;
37
    }
38
}