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

ArrayHelper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 27
rs 10
c 0
b 0
f 0
ccs 10
cts 10
cp 1
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A replaceValuesByMatchingKeys() 0 16 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
}