Passed
Push — master ( c127b0...175dae )
by Radu
01:29
created

Arrays   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 8
eloc 10
c 4
b 0
f 0
dl 0
loc 23
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isMultidimensional() 0 6 2
A get() 0 6 3
A nullToEmptyString() 0 5 3
1
<?php
2
namespace WebServCo\Framework\Utils;
3
4
final class Arrays
5
{
6
    public static function get($array, $key, $defaultValue = false)
7
    {
8
        if (!is_array($array)) {
9
            return $defaultValue;
10
        }
11
        return array_key_exists($key, $array) ? $array[$key] : $defaultValue;
12
    }
13
14
    public static function isMultidimensional($array = [])
15
    {
16
        if (empty($array)) {
17
            return false;
18
        }
19
        return is_array($array[key($array)]);
20
    }
21
22
    public static function nullToEmptyString($array = [])
23
    {
24
        foreach ($array as $key => $value) {
25
            if (is_null($value)) {
26
                $array[$key] = '';
27
            }
28
        }
29
    }
30
}
31