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::extractConfiguration()   C
last analyzed

Complexity

Conditions 13
Paths 22

Size

Total Lines 50
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 26.7484

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 50
ccs 17
cts 30
cp 0.5667
rs 5.3808
cc 13
eloc 32
nc 22
nop 5
crap 26.7484

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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