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 ( 280361...c88be9 )
by Anton
08:00
created

Host::getRealHostname()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 2
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\Host;
9
10
use Deployer\Configuration\Configuration;
11
use Deployer\Configuration\ConfigurationAccessor;
12
use Deployer\Ssh\Arguments;
13
use Deployer\Ssh\Options;
14
15
class Host
16
{
17
    use ConfigurationAccessor;
18
19
    private $hostname;
20
    private $realHostname;
21
    private $user;
22
    private $port;
23
    private $configFile;
24
    private $identityFile;
25
    private $forwardAgent = true;
26
    private $multiplexing = null;
27
    private $sshArguments;
28
29
    /**
30
     * @param string $hostname
31
     */
32 28
    public function __construct(string $hostname)
33
    {
34 28
        $this->hostname = $hostname;
35 28
        $this->setRealHostname($hostname);
36 28
        $this->config = new Configuration();
37 28
        $this->sshArguments = new Arguments();
38 28
    }
39
40 3
    private function initOptions()
41
    {
42 3
        if ($this->port) {
43 3
            $this->sshArguments = $this->sshArguments->withFlag('-p', $this->port);
44
        }
45
46 3
        if ($this->configFile) {
47 2
            $this->sshArguments = $this->sshArguments->withFlag('-F', $this->configFile);
48
        }
49
50 3
        if ($this->identityFile) {
51 2
            $this->sshArguments = $this->sshArguments->withFlag('-i', $this->identityFile);
52
        }
53
54 3
        if ($this->forwardAgent) {
55 3
            $this->sshArguments = $this->sshArguments->withFlag('-A');
56
        }
57 3
    }
58
59
    /**
60
     * Returns pair user/hostname
61
     *
62
     * @return string
63
     */
64 6
    public function __toString()
65
    {
66 6
        $user = empty($this->user) ? '' : "{$this->user}@";
67 6
        return "$user{$this->realHostname}";
68
    }
69
70
    /**
71
     * @return string
72
     */
73 23
    public function getHostname()
74
    {
75 23
        return $this->hostname;
76
    }
77
78
    /**
79
     * @return mixed
80
     */
81
    public function getRealHostname()
82
    {
83
        return $this->realHostname;
84
    }
85
86
    /**
87
     * @param string $hostname
88
     * @return $this
89
     */
90 4
    public function hostname(string $hostname)
91
    {
92 4
        $this->setRealHostname($hostname);
93 4
        return $this;
94
    }
95
96
    /**
97
     * @param mixed $hostname
98
     */
99 28
    private function setRealHostname(string $hostname)
100
    {
101 28
        $this->realHostname = preg_replace('/\/.+$/', '', $hostname);
102 28
    }
103
104
    /**
105
     * @return string
106
     */
107 2
    public function getUser()
108
    {
109 2
        return $this->user;
110
    }
111
112
    /**
113
     * @param string $user
114
     * @return $this
115
     */
116 4
    public function user(string $user)
117
    {
118 4
        $this->user = $user;
119 4
        return $this;
120
    }
121
122
    /**
123
     * @return int
124
     */
125 4
    public function getPort()
126
    {
127 4
        return $this->port;
128
    }
129
130
    /**
131
     * @param int $port
132
     * @return $this
133
     */
134 4
    public function port(int $port)
135
    {
136 4
        $this->port = $port;
137 4
        return $this;
138
    }
139
140
    /**
141
     * @return string
142
     */
143 2
    public function getConfigFile()
144
    {
145 2
        return $this->configFile;
146
    }
147
148
    /**
149
     * @param string $configFile
150
     * @return $this
151
     */
152 3
    public function configFile(string $configFile)
153
    {
154 3
        $this->configFile = $configFile;
155 3
        return $this;
156
    }
157
158
    /**
159
     * @return string
160
     */
161 2
    public function getIdentityFile()
162
    {
163 2
        return $this->identityFile;
164
    }
165
166
    /**
167
     * @param string $identityFile
168
     * @return $this
169
     */
170 3
    public function identityFile(string $identityFile)
171
    {
172 3
        $this->identityFile = $identityFile;
173 3
        return $this;
174
    }
175
176
    /**
177
     * @return bool
178
     */
179 2
    public function isForwardAgent()
180
    {
181 2
        return $this->forwardAgent;
182
    }
183
184
    /**
185
     * @param bool $forwardAgent
186
     * @return $this
187
     */
188 3
    public function forwardAgent(bool $forwardAgent = true)
189
    {
190 3
        $this->forwardAgent = $forwardAgent;
191 3
        return $this;
192
    }
193
194
    /**
195
     * @return bool
196
     */
197 2
    public function isMultiplexing()
198
    {
199 2
        return $this->multiplexing;
200
    }
201
202
    /**
203
     * @param bool $multiplexing
204
     * @return $this
205
     */
206 3
    public function multiplexing(bool $multiplexing = true)
207
    {
208 3
        $this->multiplexing = $multiplexing;
209 3
        return $this;
210
    }
211
212 3
    public function getSshArguments()
213
    {
214 3
        $this->initOptions();
215 3
        return $this->sshArguments;
216
    }
217
218 3
    public function sshOptions(array $options) : Host
219
    {
220 3
        $this->sshArguments = $this->sshArguments->withOptions($options);
221 3
        return $this;
222
    }
223
224 2
    public function sshFlags(array $flags) : Host
225
    {
226 2
        $this->sshArguments = $this->sshArguments->withFlags($flags);
227 2
        return $this;
228
    }
229
230 1
    public function addSshOption(string $option, $value) : Host
231
    {
232 1
        $this->sshArguments = $this->sshArguments->withOption($option, $value);
233 1
        return $this;
234
    }
235
236
    public function addSshFlag(string $flag, string $value = null) : Host
237
    {
238
        $this->sshArguments = $this->sshArguments->withFlag($flag, $value);
239
        return $this;
240
    }
241
242
    /**
243
     * Set stage
244
     *
245
     * @param string $stage
246
     * @return $this
247
     */
248 4
    public function stage(string $stage)
249
    {
250 4
        $this->config->set('stage', $stage);
251 4
        return $this;
252
    }
253
254
    /**
255
     * Set roles
256
     *
257
     * @param array ...$roles
258
     * @return $this
259
     */
260 4
    public function roles(...$roles)
261
    {
262 4
        $this->config->set('roles', []);
263
264 4
        foreach ($roles as $role) {
265 4
            $this->config->add('roles', [$role]);
266
        }
267
268 4
        return $this;
269
    }
270
271
    /**
272
     * Set become
273
     *
274
     * @param string $user
275
     * @return $this
276
     */
277
    public function become(string $user)
278
    {
279
        $this->config->set('become', $user);
280
        return $this;
281
    }
282
}
283