Arr   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 30
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 19 5
1
<?php
2
/**
3
 * @link https://github.com/phpviet/omnipay-momo
4
 * @copyright (c) PHP Viet
5
 * @license [MIT](http://www.opensource.org/licenses/MIT)
6
 */
7
8
namespace Omnipay\MoMo\Support;
9
10
class Arr
11
{
12
    /**
13
     * Hổ trợ lấy giá trị trong mảng với định dạng 'a.b.c'.
14
     *
15
     * @param  mixed  $element
16
     * @param  array  $arr
17
     * @param  null  $default
18
     * @return mixed
19
     */
20
    public static function getValue($element, array $arr, $default = null)
21
    {
22
        while (false !== ($pos = strpos($element, '.'))) {
23
            $sub = substr($element, 0, $pos);
24
            $element = substr($element, $pos + 1);
25
26
            if (isset($arr[$sub]) && is_array($arr[$sub])) {
27
                $arr = $arr[$sub];
28
            } else {
29
                break;
30
            }
31
        }
32
33
        if (false === strpos($element, '.')) {
34
            return $arr[$element] ?? $default;
35
        }
36
37
        return $default;
38
    }
39
}
40