Completed
Push — master ( 96ab65...e04c91 )
by Алексей
09:52
created

helpers.php ➔ get()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 18
Code Lines 8

Duplication

Lines 18
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
cc 6
eloc 8
nc 5
nop 3
dl 18
loc 18
ccs 0
cts 0
cp 0
crap 42
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
if ( ! function_exists('array_get'))
4
{
5
    /**
6
     * Get an item from an array using "dot" notation.
7
     *
8
     * @param  array   $array
9
     * @param  string  $key
10
     * @param  mixed   $default
11
     * @return mixed
12
     */
13
    function array_get($array, $key, $default = null)
14
    {
15
        if (is_null($key)) return $array;
16
17
        if (isset($array[$key])) return $array[$key];
18
19
        foreach (explode('.', $key) as $segment)
20
        {
21
            if ( ! is_array($array) || ! array_key_exists($segment, $array))
22
            {
23
                return value($default);
24
            }
25
26
            $array = $array[$segment];
27
        }
28
29
        return $array;
30
    }
31
}
32