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
Push — master ( 07fd04...6d3d42 )
by Anton
01:59
created

Application::selfUpdateCommand()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 7
ccs 0
cts 5
cp 0
crap 2
rs 10
c 0
b 0
f 0
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\Component\PharUpdate\Console\Command as PharUpdateCommand;
11
use Deployer\Component\PharUpdate\Console\Helper as PharUpdateHelper;
12
use Deployer\Deployer;
13
use Symfony\Component\Console\Application as Console;
14
use Symfony\Component\Console\Command\Command;
15
use Symfony\Component\Console\Input\InputDefinition;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Input\InputOption;
18
use Symfony\Component\Console\Output\OutputInterface;
19
20
class Application extends Console
21
{
22
    /**
23
     * Input definition for user specific arguments and options.
24
     *
25
     * @var InputDefinition
26
     */
27
    private $userDefinition;
28
29
    /**
30
     * @var callable
31
     */
32
    private $catchIO;
33
34
    /**
35
     * @var callable
36
     */
37
    private $after;
38
39
    protected function getDefaultInputDefinition()
40
    {
41
        $inputDefinition = parent::getDefaultInputDefinition();
42
43
        $inputDefinition->addOption(
44
            new InputOption('--file', '-f', InputOption::VALUE_OPTIONAL, 'Specify Deployer file')
45
        );
46
47
        return $inputDefinition;
48
    }
49
50
    protected function getDefaultCommands()
51
    {
52
        $commands = parent::getDefaultCommands();
53
54
        if ($this->isPharArchive()) {
55
            $commands[] = $this->selfUpdateCommand();
56
        }
57
58
        return $commands;
59
    }
60
61
    private function selfUpdateCommand()
62
    {
63
        $selfUpdate = new PharUpdateCommand('self-update');
64
        $selfUpdate->setDescription('Updates deployer.phar to the latest version');
65
        $selfUpdate->setManifestUri('https://deployer.org/manifest.json');
66
        return $selfUpdate;
67
    }
68
69
    protected function getDefaultHelperSet()
70
    {
71
        $helperSet = parent::getDefaultHelperSet();
72
73
        if ($this->isPharArchive()) {
74
            $helperSet->set(new PharUpdateHelper());
75
        }
76
        return $helperSet;
77
    }
78
79
    public function getUserDefinition()
80
    {
81
        if (null === $this->userDefinition) {
82
            $this->userDefinition = new InputDefinition();
83
        }
84
85
        return $this->userDefinition;
86
    }
87
88
    public function addUserArgumentsAndOptions()
89
    {
90
        $this->getDefinition()->addArguments($this->getUserDefinition()->getArguments());
91
        $this->getDefinition()->addOptions($this->getUserDefinition()->getOptions());
92
    }
93
94
    public function isPharArchive()
95
    {
96
        return 'phar:' === substr(__FILE__, 0, 5);
97
    }
98
99
    protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
100
    {
101
        $exception = null;
102
        $exitCode = 0;
103
104
        if (!empty($this->catchIO)) {
105
            list($input, $output) = call_user_func($this->catchIO, $input, $output);
106
        }
107
108
        try {
109
            $exitCode = parent::doRunCommand($command, $input, $output);
110
        } catch (\Throwable $x) {
111
            $exception = $x;
112
        }
113
114
        if (!empty($this->after)) {
115
            call_user_func($this->after, new CommandEvent($command, $input, $output, $exception, $exitCode));
116
        }
117
118
        if ($exception !== null) {
119
            throw $exception;
120
        }
121
122
        return $exitCode;
123
    }
124
125
    public function catchIO($callable)
126
    {
127
        $this->catchIO = $callable;
128
    }
129
130
    public function afterRun($callable)
131
    {
132
        $this->after = $callable;
133
    }
134
}
135