DotChainOperator   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
eloc 18
c 2
b 1
f 1
dl 0
loc 36
ccs 19
cts 19
cp 1
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A update() 0 12 2
A _h() 0 4 2
A _v() 0 13 3
1
<?php
2
3
4
namespace TKuni\PhpNormalizer\Helper;
5
6
use Closure;
7
8
class DotChainOperator
9
{
10 14
    public static function update($arr, $key, $val)
11
    {
12 14
        $separatedKeys = explode('.', $key);
13 14
        if (is_callable($val)) {
14 10
            self::_v($arr, $separatedKeys, $val);
15
        } else {
16
            self::_v($arr, $separatedKeys, function($in) use ($val) {
0 ignored issues
show
Unused Code introduced by
The parameter $in is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

16
            self::_v($arr, $separatedKeys, function(/** @scrutinizer ignore-unused */ $in) use ($val) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
17 4
                return $val;
18 4
            });
19
        }
20
21 14
        return $arr;
22
    }
23
24 14
    private static function _v(&$arr, array $keys, Closure $filter, $i = 0)
25
    {
26 14
        if (empty($keys[$i])) {
27 14
            $arr = $filter($arr);
28 14
            return;
29
        }
30
31 14
        $currKey = $keys[$i];
32
33 14
        if ($currKey === '*') {
34 10
            self::_h($arr, $keys, $filter, $i);
35
        } else {
36 14
            self::_v($arr[$currKey], $keys, $filter, $i + 1);
37
        }
38 14
    }
39
40 10
    private static function _h(&$arr, array $keys, Closure $filter, $i)
41
    {
42 10
        foreach ($arr as &$item) {
43 10
            self::_v($item, $keys, $filter, $i + 1);
44
        }
45
    }
46
}