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.
Test Failed
Push — master ( 444b11...55afa9 )
by Anton
18:50 queued 16:47
created

MainCommand   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 127
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 92.77%

Importance

Changes 0
Metric Value
dl 0
loc 127
ccs 77
cts 83
cp 0.9277
rs 10
c 0
b 0
f 0
wmc 18
lcom 1
cbo 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A configure() 0 43 1
A parseOptions() 0 8 2
A castValueToPhpType() 0 11 3
B execute() 0 51 10
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\Exception\GracefulShutdownException;
13
use Deployer\Executor\Planner;
14
use Symfony\Component\Console\Input\InputInterface as Input;
15
use Symfony\Component\Console\Input\InputOption as Option;
16
use Symfony\Component\Console\Output\OutputInterface as Output;
17
18
class MainCommand extends SelectCommand
19
{
20 8
    public function __construct(string $name, ?string $description, Deployer $deployer)
21
    {
22 8
        parent::__construct($name, $deployer);
23 8
        if ($description) {
24 8
            $this->setDescription($description);
25
        }
26 8
    }
27
28 8
    protected function configure()
29
    {
30 8
        parent::configure();
31
32
        // Add global options defined with `option()` func.
33 8
        $this->getDefinition()->addOptions($this->deployer->inputDefinition->getOptions());
34 8
        $this->addOption(
35 8
            'option',
36 8
            'o',
37 8
            Option::VALUE_REQUIRED | Option::VALUE_IS_ARRAY,
38 8
            'Sets configuration option'
39
        );
40 8
        $this->addOption(
41 8
            'limit',
42 8
            'l',
43 8
            Option::VALUE_REQUIRED,
44 8
            'How many tasks to run in parallel?'
45
        );
46 8
        $this->addOption(
47 8
            'no-hooks',
48 8
            null,
49 8
            Option::VALUE_NONE,
50 8
            'Run tasks without after/before hooks'
51
        );
52 8
        $this->addOption(
53 8
            'plan',
54 8
            null,
55 8
            Option::VALUE_NONE,
56 8
            'Show execution plan'
57
        );
58 8
        $this->addOption(
59 8
            'log',
60 8
            null,
61 8
            Option::VALUE_REQUIRED,
62 8
            'Log to file'
63
        );
64 8
        $this->addOption(
65 8
            'profile',
66 8
            null,
67 8
            Option::VALUE_REQUIRED,
68 8
            'Writes tasks profile fo PROFILE file'
69
        );
70 8
    }
71
72 7
    protected function execute(Input $input, Output $output)
73
    {
74 7
        $this->deployer->input = $input;
75 7
        $this->deployer->output = $output;
76 7
        $this->deployer->config['log_file'] = $input->getOption('log');
77 7
        $this->parseOptions($input->getOption('option'));
78
79 7
        $hosts = $this->selectHosts($input, $output);
80
81 7
        $plan = $input->getOption('plan') ? new Planner($output, $hosts) : null;
82 7
        if ($plan === null) {
83
            // Materialize hosts configs
84 7
            $configDirectory = sprintf('%s/deployer/%s/%s', sys_get_temp_dir(), uniqid(), time());
85 7
            if (!is_dir($configDirectory)) {
86 7
                mkdir($configDirectory, 0700, true);
87
            }
88 7
            $this->deployer->config->set('config_directory', $configDirectory);
0 ignored issues
show
Bug introduced by
The method set cannot be called on $this->deployer->config (of type array<string,string|arra...string>|boolean|null"}>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
89 7
            foreach ($hosts as $alias => $host) {
90 7
                $host->getConfig()->save();
91
            }
92
        }
93
94 7
        $this->deployer->scriptManager->setHooksEnabled(!$input->getOption('no-hooks'));
95 7
        $tasks = $this->deployer->scriptManager->getTasks($this->getName());
96 7
        if (empty($tasks)) {
97
            throw new Exception('No task will be executed, because the selected hosts do not meet the conditions of the tasks');
98
        }
99
100 7
        $exitCode = $this->deployer->executor->run($tasks, $hosts, $plan);
101
102 7
        if ($plan) {
103
            $plan->render();
104
            return 0;
105
        }
106
107 7
        if ($exitCode === 0) {
108 6
            return 0;
109
        }
110 1
        if ($exitCode === GracefulShutdownException::EXIT_CODE) {
111
            return 1;
112
        }
113
114
        // Check if we have tasks to execute on failure.
115 1
        if ($this->deployer['fail']->has($this->getName())) {
116 1
            $taskName = $this->deployer['fail']->get($this->getName());
117 1
            $tasks = $this->deployer->scriptManager->getTasks($taskName);
118 1
            $this->deployer->executor->run($tasks, $hosts);
119
        }
120
121 1
        return $exitCode;
122
    }
123
124 7
    protected function parseOptions(array $options)
125
    {
126 7
        foreach ($options as $option) {
127 1
            list($name, $value) = explode('=', $option);
128 1
            $value = $this->castValueToPhpType(trim($value));
129 1
            $this->deployer->config->set(trim($name), $value);
130
        }
131 7
    }
132
133 1
    protected function castValueToPhpType($value)
134
    {
135 1
        switch ($value) {
136 1
            case 'true':
137
                return true;
138 1
            case 'false':
139
                return false;
140
            default:
141 1
                return $value;
142
        }
143
    }
144
}
145