Completed
Push — master ( 829fea...03fe8f )
by Dominik
9s
created

Helpers   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A returnFirstArgumentOrNestedData() 0 8 2
B accessArrayOrObject() 0 12 7
A extractNestedDataFromArray() 0 9 2
A returnEmptyStringOrFirstArgument() 0 9 3
1
<?php
2
3
namespace Flynt;
4
5
class Helpers
6
{
7
    public static function extractNestedDataFromArray($args = [])
8
    {
9
        if (count($args) < 2) {
10
            return self::returnEmptyStringOrFirstArgument($args);
11
        }
12
        $key = array_pop($args);
13
        $data = self::returnFirstArgumentOrNestedData($args);
14
        return self::accessArrayOrObject($key, $data);
15
    }
16
17
    protected static function returnEmptyStringOrFirstArgument($args = [])
18
    {
19
        if (count($args) === 0) {
20
            return '';
21
        }
22
        if (count($args) === 1) {
23
            return $args[0];
24
        }
25
    }
26
27
    protected static function returnFirstArgumentOrNestedData($args = [])
28
    {
29
        if (count($args) > 1) {
30
            return self::extractNestedDataFromArray($args);
31
        } else {
32
            return $args[0];
33
        }
34
    }
35
36
    protected static function accessArrayOrObject($key, $data)
37
    {
38
        $output = '';
39
        if (is_array($key) || is_object($key)) {
40
            $output = $key;
41
        } elseif (is_array($data) && array_key_exists($key, $data)) {
42
            $output = $data[$key];
43
        } elseif (is_object($data) && property_exists($data, $key)) {
44
            $output = $data->$key;
45
        }
46
        return $output;
47
    }
48
}
49