Completed
Push — analysis-zO3Kk0 ( d732ee )
by Fabrizio
05:03 queued 02:48
created

helpers.php ➔ notifynder_mixed_get()   C

Complexity

Conditions 14
Paths 7

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
cc 14
eloc 15
c 2
b 1
f 1
nc 7
nop 3
dl 0
loc 21
rs 6.5272

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
if (! function_exists('notifynder_config')) {
4
    /**
5
     * @param null|string $key
6
     * @param null|mixed $default
7
     * @return mixed|\Fenos\Notifynder\Contracts\ConfigContract
8
     */
9
    function notifynder_config($key = null, $default = null)
10
    {
11
        $config = app('notifynder.config');
12
        if (is_null($key)) {
13
            return $config;
14
        }
15
16
        return $config->get($key, $default);
17
    }
18
}
19
20
if (! function_exists('notifynder_mixed_get')) {
21
    function notifynder_mixed_get($object, $key, $default = null)
22
    {
23
        if (is_null($key) || trim($key) == '') {
24
            return '';
25
        }
26
        foreach (explode('.', $key) as $segment) {
27
            if (is_object($object) && isset($object->{$segment})) {
28
                $object = $object->{$segment};
29
            } elseif (is_object($object) && method_exists($object, '__get') && ! is_null($object->__get($segment))) {
30
                $object = $object->__get($segment);
31
            } elseif (is_object($object) && method_exists($object, 'getAttribute') && ! is_null($object->getAttribute($segment))) {
32
                $object = $object->getAttribute($segment);
33
            } elseif (is_array($object) && array_key_exists($segment, $object)) {
34
                $object = array_get($object, $segment, $default);
35
            } else {
36
                return value($default);
37
            }
38
        }
39
40
        return $object;
41
    }
42
}
43