Completed
Push — master ( e0a87f...bae2c1 )
by Sergey
04:47 queued 02:15
created

ArrayHelper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 25
rs 10
c 1
b 0
f 0
wmc 4
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getValueByKey() 0 16 4
1
<?php
2
3
namespace seregazhuk\PinterestBot\Helpers;
4
5
class ArrayHelper
6
{
7
    /**
8
     * @param string $key
9
     * @param array $data
10
     * @param mixed $default
11
     * @return array|bool|mixed
12
     */
13
    public static function getValueByKey($key = '', $data, $default = null)
14
    {
15
        if(empty($key)) return $data;
16
17
        $indexes = explode('.', $key);
18
19
        $value = $data;
20
21
        foreach ($indexes as $index) {
22
            if(!isset($value[$index])) return $default;
23
24
            $value = $value[$index];
25
        }
26
27
        return $value;
28
    }
29
}