GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ConfigListCommand   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 68.28%

Importance

Changes 6
Bugs 2 Features 1
Metric Value
wmc 15
c 6
b 2
f 1
lcom 2
cbo 3
dl 0
loc 89
ccs 28
cts 41
cp 0.6828
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 11 1
A execute() 0 6 1
C extractConfiguration() 0 50 13
1
<?php
2
3
/*
4
 * This file is part of the slack-cli package.
5
 *
6
 * (c) Cas Leentfaar <[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
namespace CL\SlackCli\Command;
13
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
/**
18
 * @author Cas Leentfaar <[email protected]>
19
 */
20
class ConfigListCommand extends AbstractCommand
21
{
22
    /**
23
     * {@inheritDoc}
24
     */
25 1
    protected function configure()
26
    {
27 1
        parent::configure();
28
29 1
        $this->setName('config:list');
30 1
        $this->setDescription('Lists all the keys and values from the global configuration');
31 1
        $this->setHelp(<<<EOT
32
The <info>config:list</info> command lists all the keys and values from the global configuration.
33
EOT
34 1
        );
35 1
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 1
    public function execute(InputInterface $input, OutputInterface $output)
41
    {
42 1
        $rows = $this->extractConfiguration($this->getConfig()->all(), $this->getConfig()->raw(), $output);
43
        
44 1
        $this->createKeyValueTable($rows)->render();
45 1
    }
46
47
    /**
48
     * Extracts the contents of the configuration file recursively
49
     *
50
     * @param array           $contents
51
     * @param array           $rawContents
52
     * @param OutputInterface $output
53
     * @param string|null     $k
54
     * @param array           $currentRows
55
     *
56
     * @return array
57
     */
58 1
    private function extractConfiguration(
59
        array $contents,
60
        array $rawContents,
61
        OutputInterface $output,
62
        $k = null,
63
        &$currentRows = []
64
    ) {
65 1
        $origK = $k;
66 1
        foreach ($contents as $key => $value) {
67 1
            if ($k === null && !in_array($key, array('config'))) {
68
                continue;
69
            }
70
71 1
            $rawVal = isset($rawContents[$key]) ? $rawContents[$key] : null;
72
73 1
            if (is_array($value) && (!is_numeric(key($value)))) {
74 1
                $k .= preg_replace('{^config\.}', '', $key . '.');
75 1
                $this->extractConfiguration($value, $rawVal, $output, $k, $currentRows);
76
77 1
                if (substr_count($k, '.') > 1) {
78
                    $k = str_split($k, strrpos($k, '.', -2));
79
                    $k = $k[0] . '.';
80
                } else {
81 1
                    $k = $origK;
82
                }
83
84 1
                continue;
85
            }
86
87 1
            if (is_array($value)) {
88
                $value = array_map(function ($val) {
89
                    return is_array($val) ? json_encode($val) : $val;
90
                }, $value);
91
92
                $value = '[' . implode(', ', $value) . ']';
93
            }
94
95 1
            if (is_bool($value)) {
96
                $value = var_export($value, true);
97
            }
98
99 1
            if (is_string($rawVal) && $rawVal != $value) {
100
                $currentRows[$k . $key] = $rawVal . ' (' . $value . ')';
101
            } else {
102 1
                $currentRows[$k . $key] = $value;
103
            }
104 1
        }
105
106 1
        return $currentRows;
107
    }
108
}
109