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.

ConfigSetCommand   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 90.91%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 7
c 4
b 0
f 1
lcom 2
cbo 3
dl 0
loc 69
ccs 30
cts 33
cp 0.9091
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 15 1
A execute() 0 7 1
B setConfig() 0 36 5
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\InputArgument;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Output\OutputInterface;
17
18
/**
19
 * @author Cas Leentfaar <[email protected]>
20
 */
21
class ConfigSetCommand extends AbstractCommand
22
{
23
    /**
24
     * {@inheritDoc}
25
     */
26 1
    protected function configure()
27
    {
28 1
        parent::configure();
29
30 1
        $this->setName('config:set');
31 1
        $this->setDescription('Stores the given setting and value in the global configuration');
32 1
        $this->addArgument('setting', InputArgument::REQUIRED, 'The setting to use');
33 1
        $this->addArgument('value', InputArgument::REQUIRED, 'The value to set for this setting');
34 1
        $this->setHelp(<<<EOT
35
The <info>config:set</info> command lets you store a given setting and value in the global configuration.
36
37
To list all stored settings and values, use the <info>config.list</info> command.
38
EOT
39 1
        );
40 1
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 1
    public function execute(InputInterface $input, OutputInterface $output)
46
    {
47 1
        $setting = $this->input->getArgument('setting');
48 1
        $value   = $this->input->getArgument('value');
49
50 1
        return $this->setConfig($setting, $value);
51
    }
52
53
    private function setConfig($setting, $value)
54
    {
55
        // handle config values
56
        $uniqueConfigValues = [
57 1
            'default_token' => ['is_string', function ($val) {
58 1
                return $val;
59 1
            }],
60 1
        ];
61
62 1
        foreach ($uniqueConfigValues as $name => $callbacks) {
63 1
            if ($setting === $name) {
64 1
                list($validator, $normalizer) = $callbacks;
65
66 1
                if (true !== $validation = $validator($value)) {
67
                    throw new \RuntimeException(sprintf(
68
                        '"%s" is an invalid value' . ($validation ? ' (' . $validation . ')' : ''),
69
                        $value
70
                    ));
71
                }
72
73 1
                $this->getConfigSource()->addConfigSetting($setting, $normalizer($value));
74
75 1
                $this->writeOk(sprintf(
76 1
                    'Successfully changed value of <info>`%s`</info> to <comment>`%s`</comment>!',
77 1
                    $setting,
78
                    $value
79 1
                ));
80
81 1
                return 0;
82
            }
83 1
        }
84
85 1
        $this->writeError(sprintf('There is no setting with that name in the configuration: `%s`', $setting));
86
87 1
        return 1;
88
    }
89
}
90