helpers.php ➔ array_get()   B
last analyzed

Complexity

Conditions 6
Paths 5

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 7.3329

Importance

Changes 0
Metric Value
cc 6
eloc 8
nc 5
nop 3
dl 0
loc 18
ccs 6
cts 9
cp 0.6667
crap 7.3329
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 6
        if (is_null($key)) return $array;
16
17 6
        if (isset($array[$key])) return $array[$key];
18
19 5
        foreach (explode('.', $key) as $segment)
20
        {
21 5
            if ( ! is_array($array) || ! array_key_exists($segment, $array))
22 5
            {
23 5
                return value($default);
24
            }
25
26
            $array = $array[$segment];
27
        }
28
29
        return $array;
30
    }
31
}
32
33
34
if ( ! function_exists('snake_case'))
35
{
36
        function snake_case($value, $delimiter = '_')
37
        {
38 3
        	$replace = '$1'.$delimiter.'$2';
39 3
        	return ctype_lower($value) ? $value : strtolower(preg_replace('/(.)([A-Z])/', $replace, $value));
40
        }
41
}
42