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 ( 99078a...9605c1 )
by Oanh
02:49
created

Deployer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
ccs 13
cts 13
cp 1
rs 9.4285
cc 1
eloc 12
nc 1
nop 3
crap 1
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;
9
10
use Deployer\Console\InitCommand;
11
use Deployer\Console\WorkerCommand;
12
use Deployer\Console\Application;
13
use Deployer\Server;
14
use Deployer\Stage\StageStrategy;
15
use Deployer\Task;
16
use Deployer\Collection;
17
use Deployer\Console\TaskCommand;
18
use Symfony\Component\Console;
19
20
/**
21
 * @property Task\TaskCollection|Task\Task[] $tasks
22
 * @property Task\Scenario\ScenarioCollection|Task\Scenario\Scenario[] $scenarios
23
 * @property Server\ServerCollection|Server\ServerInterface[] $servers
24
 * @property Server\EnvironmentCollection|Server\Environment[] $environments
25
 * @property Collection\Collection $parameters
26
 */
27
class Deployer
28
{
29
    /**
30
     * Global instance of deployer. It's can be accessed only after constructor call.
31
     * @var Deployer
32
     */
33
    private static $instance;
34
35
    /**
36
     * @var Application
37
     */
38
    private $console;
39
40
    /**
41
     * @var Console\Input\InputInterface
42
     */
43
    private $input;
44
45
    /**
46
     * @var Console\Output\OutputInterface
47
     */
48
    private $output;
49
50
    /**
51
     * @var Collection\Collection
52
     */
53
    private $collections;
54
55
    /**
56
     * @var StageStrategy
57
     */
58
    private $stageStrategy;
59
60
    /**
61
     * @param Application $console
62
     * @param Console\Input\InputInterface $input
63
     * @param Console\Output\OutputInterface $output
64
     */
65 31
    public function __construct(Application $console, Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
66
    {
67 31
        $this->console = $console;
68 31
        $this->input = $input;
69 31
        $this->output = $output;
70
71 31
        $this->collections = new Collection\Collection();
72 31
        $this->collections['tasks'] = new Task\TaskCollection();
73 31
        $this->collections['scenarios'] = new Task\Scenario\ScenarioCollection();
74 31
        $this->collections['servers'] = new Server\ServerCollection();
75 31
        $this->collections['environments'] = new Server\EnvironmentCollection();
76 31
        $this->collections['parameters'] = new Collection\Collection();
77
78 31
        $this->stageStrategy = new StageStrategy($this->servers, $this->environments, $this->parameters);
79
80 31
        self::$instance = $this;
81 31
    }
82
83
    /**
84
     * @return Deployer
85
     */
86 20
    public static function get()
87
    {
88 20
        return self::$instance;
89
    }
90
91
    /**
92
     * Run console application.
93
     */
94
    public function run()
95
    {
96
        $this->addConsoleCommands();
97
        
98
        $this->console->add(new WorkerCommand($this));
99
        $this->console->add(new InitCommand());
100
101
        $this->console->run($this->input, $this->output);
102
    }
103
104
    /**
105
     * Transform tasks to console commands.
106
     */
107 13
    public function addConsoleCommands()
108
    {
109 13
        $this->console->addUserArgumentsAndOptions();
110
        
111 13
        foreach ($this->tasks as $name => $task) {
112 13
            if ($task->isPrivate()) {
113 13
                continue;
114
            }
115
            
116 13
            $this->console->add(new TaskCommand($name, $task->getDescription(), $this));
117 13
        }
118 13
    }
119
120
    /**
121
     * @return Console\Input\InputInterface
122
     */
123
    public function getInput()
124
    {
125
        return $this->input;
126
    }
127
128
    /**
129
     * @return Console\Output\OutputInterface
130
     */
131
    public function getOutput()
132
    {
133
        return $this->output;
134
    }
135
136
    /**
137
     * @param string $name
138
     * @return mixed
139
     * @throws \InvalidArgumentException
140
     */
141 31
    public function __get($name)
142
    {
143 31
        if ($this->collections->has($name)) {
144 31
            return $this->collections[$name];
145
        } else {
146 1
            throw new \InvalidArgumentException("Property \"$name\" does not exist.");
147
        }
148
    }
149
150
    /**
151
     * @param string $name
152
     * @return Console\Helper\HelperInterface
153
     */
154
    public function getHelper($name)
155
    {
156
        return $this->console->getHelperSet()->get($name);
157
    }
158
159
    /**
160
     * @return Application
161
     */
162 13
    public function getConsole()
163
    {
164 13
        return $this->console;
165
    }
166
167
    /**
168
     * @return StageStrategy
169
     */
170 14
    public function getStageStrategy()
171
    {
172 14
        return $this->stageStrategy;
173
    }
174
}
175