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

Config   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 3
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A processCommand() 0 8 2
B printArray() 0 21 8
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