Helper::toArray()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
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