Helper   A
last analyzed

Coupling/Cohesion

Components 0
Dependencies 0

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 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 956
    public static function toArray($var)
13
    {
14 956
        if (!is_array($var)) {
15 956
            return [$var];
16
        }
17
18 584
        return $var;
19
    }
20
21
    /**
22
     * Flatten a multi-dimensional array
23
     *
24
     * @param array $arr
25
     *
26
     * @return array
27
     */
28 956
    public static function flatten(array $arr)
29
    {
30 956
        $flattened = [];
31
32 956
        array_walk_recursive($arr, function ($a) use (&$flattened) {
33 956
            $flattened[] = $a;
34 956
        });
35
36 956
        return $flattened;
37
    }
38
39
    /**
40
     * Convert a string to snake case
41
     *
42
     * @param string $str
43
     *
44
     * @return string
45
     */
46 564
    public static function snakeCase($str)
47
    {
48 564
        return strtolower(preg_replace('/(.)([A-Z])/', '$1_$2', $str));
49
    }
50
}
51