Helper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 46
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 8 2
A flatten() 0 10 1
A snakeCase() 0 4 1
1
<?php
2
3
namespace League\CLImate\Util;
4
5
class Helper
6
{
7
    /**
8
     * @param string|array $var
9
     *
10
     * @return array
11
     */
12 972
    public static function toArray($var)
13
    {
14 972
        if (!is_array($var)) {
15 972
            return [$var];
16
        }
17
18 600
        return $var;
19
    }
20
21
    /**
22
     * Flatten a multi-dimensional array
23
     *
24
     * @param array $arr
25
     *
26
     * @return array
27
     */
28 972
    public static function flatten(array $arr)
29
    {
30 972
        $flattened = [];
31
32 972
        array_walk_recursive($arr, function ($a) use (&$flattened) {
33 972
            $flattened[] = $a;
34 972
        });
35
36 972
        return $flattened;
37
    }
38
39
    /**
40
     * Convert a string to snake case
41
     *
42
     * @param string $str
43
     *
44
     * @return string
45
     */
46 580
    public static function snakeCase($str)
47
    {
48 580
        return strtolower(preg_replace('/(.)([A-Z])/', '$1_$2', $str));
49
    }
50
}
51