Completed
Push — cmd-config ( 294155 )
by Arnaud
01:51
created

Config::printArray()   B

Complexity

Conditions 8
Paths 2

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 8.4444
c 0
b 0
f 0
cc 8
nc 2
nop 2
1
<?php
2
/*
3
 * This file is part of the PHPoole package.
4
 *
5
 * Copyright (c) Arnaud Ligny <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace PHPoole\Command;
12
13
class Config extends AbstractCommand
14
{
15
    public function processCommand()
16
    {
17
        try {
18
            $this->wl($this->printArray($this->getPHPoole()->getConfig()->getAllAsArray()));
19
        } catch (\Exception $e) {
20
            throw new \Exception(sprintf($e->getMessage()));
21
        }
22
    }
23
24
    private function printArray($array, $column = -4)
25
    {
26
        $output = '';
27
28
        if (is_array($array)) {
29
            $column += 4;
30
            foreach ($array as $key=>$val) {
31
                if (is_array($val)) {
32
                    $output .= str_repeat(' ', $column)."$key:\n".$this->printArray($val, $column);
33
                }
34
                if (is_string($val) || is_int($val)) {
35
                    $output .= str_repeat(' ', $column)."$key: $val\n";
36
                }
37
                if (is_bool($val)) {
38
                    $output .= str_repeat(' ', $column)."$key: ".($val ? 'true' : 'false')."\n";
39
                }
40
            }
41
        }
42
43
        return $output;
44
    }
45
}
46