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.
Passed
Pull Request — master (#1904)
by Anton
02:17
created

RunCommand   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 12

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 68
ccs 0
cts 54
cp 0
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 12

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 0 20 1
B execute() 0 35 7
1
<?php
2
/* (c) Anton Medvedev <[email protected]>
3
 *
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace Deployer\Console;
9
10
use Deployer\Deployer;
11
use Deployer\Exception\Exception;
12
use Deployer\Task\Context;
13
use Deployer\Task\Task;
14
use Symfony\Component\Console\Command\Command;
15
use Symfony\Component\Console\Input\InputArgument;
16
use Symfony\Component\Console\Input\InputInterface as Input;
17
use Symfony\Component\Console\Input\InputOption as Option;
18
use Symfony\Component\Console\Output\OutputInterface as Output;
19
use function Deployer\run;
20
use function Deployer\write;
21
use function Deployer\writeln;
22
23
class RunCommand extends Command
24
{
25
    private $deployer;
26
27
    public function __construct(Deployer $deployer)
28
    {
29
        parent::__construct('run');
30
        $this->setDescription('Run any arbitrary command on hosts');
31
        $this->deployer = $deployer;
32
    }
33
34
    protected function configure()
35
    {
36
        $this->addArgument(
37
            'command-to-run',
38
            InputArgument::REQUIRED | InputArgument::IS_ARRAY,
39
            'Command to run'
40
        );
41
        $this->addOption(
42
            'hosts',
43
            null,
44
            Option::VALUE_REQUIRED,
45
            'Host to deploy, comma separated, supports ranges [:]'
46
        );
47
        $this->addOption(
48
            'roles',
49
            null,
50
            Option::VALUE_REQUIRED,
51
            'Roles to deploy'
52
        );
53
    }
54
55
    protected function execute(Input $input, Output $output)
56
    {
57
        $command = implode(' ', $input->getArgument('command-to-run'));
58
        $byHosts = $input->getOption('hosts');
59
        $byRoles = $input->getOption('roles');
60
61
        if ($output->getVerbosity() === Output::VERBOSITY_NORMAL) {
62
            $output->setVerbosity(Output::VERBOSITY_VERBOSE);
63
        }
64
65
        foreach ($this->deployer->console->getUserDefinition()->getOptions() as $option) {
66
            if (!empty($input->getOption($option->getName()))) {
67
                $this->deployer->config[$option->getName()] = $input->getOption($option->getName());
68
            }
69
        }
70
71
        $hosts = $this->deployer->hostSelector->select($byHosts, $byRoles);
72
        if (empty($hosts)) {
73
            throw new Exception('No host selected');
74
        }
75
76
        $task = new Task($command, function () use ($command, $hosts) {
77
            run($command);
78
        });
79
80
        foreach ($hosts as $host) {
81
            try {
82
                $task->run(new Context($host, $input, $output));
83
            } catch (\Throwable $exception) {
84
                $this->deployer->informer->taskException($exception, $host);
85
            }
86
        }
87
88
        return 0;
89
    }
90
}
91