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::execute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
crap 1
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