Passed
Push — master ( d9423e...3d42cd )
by Lukas
04:29
created

Arr::setValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 3
crap 2
1
<?php
2
3
namespace Lneicelis\Transformer\Helper;
4
5
class Arr
6
{
7 3
    public static function setValue(array $array, array $path, $value): array
8
    {
9 3
        $lastKey = array_pop($path);
10 3
        $current = &$array;
11
12 3
        foreach($path as $key) {
13 3
            $current = &$current[$key];
14
        }
15
16 3
        $current[$lastKey] = $value;
17
18 3
        return $array;
19
    }
20
}
21