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.
Completed
Push — master ( 9656b1...f868b2 )
by Anton
03:37
created

TaskCommand   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 95
ccs 29
cts 29
cp 1
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 0 9 1
B execute() 0 54 9
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\GracefulShutdownException;
12
use Deployer\Executor\ExecutorInterface;
13
use Deployer\Executor\ParallelExecutor;
14
use Deployer\Executor\SeriesExecutor;
15
use Monolog\Logger;
16
use Symfony\Component\Console\Command\Command;
17
use Symfony\Component\Console\Input\InputInterface as Input;
18
use Symfony\Component\Console\Input\InputOption as Option;
19
use Symfony\Component\Console\Output\OutputInterface as Output;
20
21
class TaskCommand extends Command
22
{
23
    /**
24
     * @var Deployer
25
     */
26
    private $deployer;
27
28
    /**
29
     * @var ExecutorInterface
30
     */
31
    public $executor;
32
33
    /**
34
     * @param string $name
35
     * @param string $description
36 15
     * @param Deployer $deployer
37
     */
38 15
    public function __construct($name, $description, Deployer $deployer)
39 15
    {
40 15
        parent::__construct($name);
41 15
        $this->setDescription($description);
42
        $this->deployer = $deployer;
43
    }
44
45
    /**
46 15
     * Configures the command
47
     */
48 15
    protected function configure()
49 15
    {
50 15
        $this->addOption(
51 15
            'parallel',
52
            'p',
53 15
            Option::VALUE_NONE,
54 15
            'Run tasks in parallel.'
55
        );
56
    }
57
58
    /**
59 15
     * {@inheritdoc}
60
     */
61 15
    protected function execute(Input $input, Output $output)
62 15
    {
63 15
        $stage = $input->hasArgument('stage') ? $input->getArgument('stage') : null;
64 15
65
        $tasks = $this->deployer->getScriptManager()->getTasks($this->getName(), $stage);
66 15
        $servers = $this->deployer->getStageStrategy()->getServers($stage);
67
        $environments = iterator_to_array($this->deployer->environments);
68 15
69
        // Validation
70 15
        $sshType = \Deployer\get('ssh_type');
71
        if ($sshType !== 'native') {
72 15
            $output->write(
73 1
                "<comment>Warning: ssh type `$sshType` will be deprecated in Deployer 5.\n" .
74 1
                "Add this lines to your deploy.php file:\n" .
75 15
                "\n" .
76 2
                "    <fg=white>set(<fg=cyan>'ssh_type'</fg=cyan>, <fg=cyan>'native'</fg=cyan>);\n" .
77 2
                "    set(<fg=cyan>'ssh_multiplexing'</fg=cyan>, <fg=magenta;options=bold>true</fg=magenta;options=bold>);</fg=white>\n" .
78 12
                "\n" .
79
                "More info here: https://goo.gl/ya8rKW" .
80
                "</comment>\n"
81
            );
82 15
        }
83 15
84
        if (isset($this->executor)) {
85
            $executor = $this->executor;
86
        } else {
87
            if ($input->getOption('parallel')) {
88
                $executor = new ParallelExecutor($this->deployer->getConsole()->getUserDefinition());
89
            } else {
90
                $executor = new SeriesExecutor();
91
            }
92
        }
93
94
        try {
95
            $executor->run($tasks, $servers, $environments, $input, $output);
96
        } catch (\Exception $exception) {
97
            \Deployer\logger($exception->getMessage(), Logger::ERROR);
98
99
            if (!($exception instanceof GracefulShutdownException)) {
100
                // Check if we have tasks to execute on failure.
101
                if ($this->deployer['onFailure']->has($this->getName())) {
102
                    $taskName = $this->deployer['onFailure']->get($this->getName());
103
                    $tasks = $this->deployer->getScriptManager()->getTasks($taskName, $stage);
104
                    $executor->run($tasks, $servers, $environments, $input, $output);
105
                }
106
            }
107
108
            throw $exception;
109
        }
110
111
        if (Deployer::hasDefault('terminate_message')) {
112
            $output->writeln(Deployer::getDefault('terminate_message'));
113
        }
114
    }
115
}
116