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.

ConfigCommand   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 38
dl 0
loc 56
c 0
b 0
f 0
rs 10
wmc 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 5 1
B execute() 0 41 8
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/* (c) Anton Medvedev <[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 Deployer\Command;
12
13
use Deployer\Deployer;
14
use Deployer\Exception\WillAskUser;
15
use Deployer\Task\Context;
16
use Symfony\Component\Console\Input\InputInterface as Input;
17
use Symfony\Component\Console\Input\InputOption;
18
use Symfony\Component\Console\Output\NullOutput;
19
use Symfony\Component\Console\Output\OutputInterface as Output;
20
use Symfony\Component\Yaml\Yaml;
21
22
class ConfigCommand extends SelectCommand
23
{
24
    public function __construct(Deployer $deployer)
25
    {
26
        parent::__construct('config', $deployer);
27
        $this->setDescription('Get all configuration options for hosts');
28
    }
29
30
    protected function configure()
31
    {
32
        parent::configure();
33
        $this->addOption('format', null, InputOption::VALUE_OPTIONAL, 'The output format (json, yaml)', 'yaml');
34
        $this->getDefinition()->getArgument('selector')->setDefault(['all']);
35
    }
36
37
    protected function execute(Input $input, Output $output): int
38
    {
39
        $this->deployer->input = $input;
40
        $this->deployer->output = new NullOutput();
41
        $hosts = $this->selectHosts($input, $output);
42
        $data = [];
43
        $keys = $this->deployer->config->keys();
44
        define('DEPLOYER_NO_ASK', true);
45
        foreach ($hosts as $host) {
46
            Context::push(new Context($host));
47
            $values = [];
48
            foreach ($keys as $key) {
49
                try {
50
                    $values[$key] = $host->get($key);
51
                } catch (WillAskUser $exception) {
52
                    $values[$key] = ['ask' => $exception->getMessage()];
53
                } catch (\Throwable $exception) {
54
                    $values[$key] = ['error' => $exception->getMessage()];
55
                }
56
            }
57
            foreach ($host->config()->persist() as $k => $v) {
58
                $values[$k] = $v;
59
            }
60
            ksort($values);
61
            $data[$host->getAlias()] = $values;
62
            Context::pop();
63
        }
64
        $format = $input->getOption('format');
65
        switch ($format) {
66
            case 'json':
67
                $output->writeln(json_encode($data, JSON_PRETTY_PRINT));
68
                break;
69
70
            case 'yaml':
71
                $output->write(Yaml::dump($data));
72
                break;
73
74
            default:
75
                throw new \Exception("Unknown format: $format.");
76
        }
77
        return 0;
78
    }
79
}
80