ArrayConverter   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 15
c 1
b 0
f 0
dl 0
loc 32
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A recursive() 0 20 6
1
<?php
2
3
/*
4
 * This file is part of the SexyField package.
5
 *
6
 * (c) Dion Snoeijen <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare (strict_types = 1);
13
14
namespace Tardigrades\Helper;
15
16
class ArrayConverter
17
{
18
    private static $value = '';
19
20
    /**
21
     * This helper converts a (part of) a configuration array to a string
22
     * The config elements will be listed and shown when using a console command
23
     *
24
     * @param array $array
25
     * @param int $level
26
     * @return string
27
     */
28
    public static function recursive(array $array, int $level = 1): string
29
    {
30
        if ($level === 1) {
31
            self::$value = '';
32
        }
33
34
        foreach ($array as $key => $value) {
35
            if (is_array($value)) {
36
                self::$value .= str_repeat('-', $level - 1) .
37
                    (($level - 1 > 0) ? ' ' : '') .
38
                    $key . ':' . PHP_EOL;
39
                self::recursive($value, $level + 1);
40
            } else {
41
                self::$value .= str_repeat('-', $level - 1) .
42
                    (($level - 1 > 0) ? ' ' : '') .
43
                    $key . ':' . $value . PHP_EOL;
44
            }
45
        }
46
47
        return self::$value;
48
    }
49
}
50