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 ( c1a124...a29f3e )
by Anton
33s
created

Configuration::setPty()   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
dl 0
loc 4
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
/**
4
 * (c) Anton Medvedev <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Deployer\Server;
11
12
use Deployer\Server\Password\PasswordGetterInterface;
13
14
/**
15
 * Server configuration
16
 */
17
class Configuration
18
{
19
    const AUTH_BY_PASSWORD                      = 0;
20
    const AUTH_BY_CONFIG                        = 1;
21
    const AUTH_BY_IDENTITY_FILE                 = 2;
22
    const AUTH_BY_PEM_FILE                      = 3;
23
    const AUTH_BY_AGENT                         = 4;
24
    const AUTH_BY_IDENTITY_FILE_AND_PASSWORD    = 5;
25
26
    /**
27
     * Type of authentication.
28
     * By default try to connect via password authentication
29
     *
30
     * @var int
31
     */
32
    private $authenticationMethod = self::AUTH_BY_PASSWORD;
33
34
    /**
35
     * Server name
36
     *
37
     * @var string
38
     */
39
    private $name;
40
41
    /**
42
     * Server host.
43
     *
44
     * @var string
45
     */
46
    private $host;
47
48
    /**
49
     * Server port.
50
     *
51
     * @var int
52
     */
53
    private $port;
54
55
    /**
56
     * User of remote server.
57
     *
58
     * @var string
59
     */
60
    private $user;
61
62
    /**
63
     * Used for authentication with password.
64
     *
65
     * @var string
66
     */
67
    private $password;
68
69
    /**
70
     * Used for authentication with config file.
71
     *
72
     * @var string
73
     */
74
    private $configFile;
75
76
    /**
77
     * Used for authentication with public key.
78
     *
79
     * @var string
80
     */
81
    private $publicKey;
82
83
    /**
84
     * Used for authentication with public key.
85
     *
86
     * @var string
87
     */
88
    private $privateKey;
89
90
    /**
91
     * Used for authentication with public key.
92
     *
93
     * @var string
94
     */
95
    private $passPhrase;
96
97
    /**
98
     * Pem file.
99
     *
100
     * @var string
101
     */
102
    private $pemFile;
103
104
    /**
105
     * Pty configuration
106
     *
107
     * @var mixed
108
     */
109
    private $pty = null;
110
111
112
    /**
113
     * Construct
114
     *
115
     * @param string $name
116
     * @param string $host
117
     * @param int    $port
118
     */
119 23
    public function __construct($name, $host, $port = 22)
120
    {
121 23
        $this->setName($name);
122 23
        $this->setHost($host);
123 23
        $this->setPort($port);
124 23
    }
125
126
    /**
127
     * Get authentication method
128
     *
129
     * @return int
130
     */
131 1
    public function getAuthenticationMethod()
132
    {
133 1
        return $this->authenticationMethod;
134
    }
135
136
    /**
137
     * Set authentication method
138
     *
139
     * @param int $authenticationMethod
140
     *
141
     * @return Configuration
142
     */
143 2
    public function setAuthenticationMethod($authenticationMethod)
144
    {
145 2
        $this->authenticationMethod = $authenticationMethod;
146
147 2
        return $this;
148
    }
149
150
    /**
151
     * Get configuration file
152
     *
153
     * @return string
154
     */
155 1
    public function getConfigFile()
156
    {
157 1
        return $this->configFile;
158
    }
159
160
    /**
161
     * Set configuration file
162
     *
163
     * @param string $configFile
164
     *
165
     * @return Configuration
166
     */
167 1
    public function setConfigFile($configFile)
168
    {
169 1
        $this->configFile = $this->parseHome($configFile);
170
171 1
        return $this;
172
    }
173
174
    /**
175
     * Get host for connection
176
     *
177
     * @return string
178
     */
179 23
    public function getHost()
180
    {
181 23
        return $this->host;
182
    }
183
184
    /**
185
     * Set host for connection
186
     *
187
     * @param string $host
188
     *
189
     * @return Configuration
190
     */
191 23
    public function setHost($host)
192
    {
193 23
        $this->host = $host;
194
195 23
        return $this;
196
    }
197
198
    /**
199
     * Get password for connection
200
     *
201
     * @return string
202
     */
203 2
    public function getPassword()
204
    {
205 2
        return $this->getRealPassword($this->password);
206
    }
207
208
    /**
209
     * Set password for connection
210
     *
211
     * @param string $password
212
     *
213
     * @return Configuration
214
     */
215 3
    public function setPassword($password)
216
    {
217 3
        $this->password = $password;
218
219 3
        return $this;
220
    }
221
222
    /**
223
     * Get port
224
     *
225
     * @return int
226
     */
227 21
    public function getPort()
228
    {
229 21
        return $this->port;
230
    }
231
232
    /**
233
     * Set port for connection
234
     *
235
     * @param int $port
236
     *
237
     * @return Configuration
238
     */
239 23
    public function setPort($port)
240
    {
241 23
        $this->port = $port;
242
243 23
        return $this;
244
    }
245
246
    /**
247
     * Get public key
248
     *
249
     * @return string
250
     */
251 1
    public function getPublicKey()
252
    {
253 1
        return $this->publicKey;
254
    }
255
256
    /**
257
     * Set public key
258
     *
259
     * @param string $path
260
     *
261
     * @return Configuration
262
     */
263 2
    public function setPublicKey($path)
264
    {
265 2
        $this->publicKey = $this->parseHome($path);
266
267 2
        return $this;
268
    }
269
270
    /**
271
     * Get pass phrase
272
     *
273
     * @return string
274
     */
275 2
    public function getPassPhrase()
276
    {
277 2
        return $this->getRealPassword($this->passPhrase);
278
    }
279
280
    /**
281
     * Set pass phrase
282
     *
283
     * @param string $passPhrase
284
     *
285
     * @return Configuration
286
     */
287 3
    public function setPassPhrase($passPhrase)
288
    {
289 3
        $this->passPhrase = $passPhrase;
290
291 3
        return $this;
292
    }
293
294
    /**
295
     * Get private key
296
     *
297
     * @return string
298
     */
299 1
    public function getPrivateKey()
300
    {
301 1
        return $this->privateKey;
302
    }
303
304
    /**
305
     * Set private key
306
     *
307
     * @param string $path
308
     *
309
     * @return Configuration
310
     */
311 2
    public function setPrivateKey($path)
312
    {
313 2
        $this->privateKey = $this->parseHome($path);
314
315 2
        return $this;
316
    }
317
318
    /**
319
     * Get user
320
     *
321
     * @return string
322
     */
323 3
    public function getUser()
324
    {
325 3
        return $this->user;
326
    }
327
328
    /**
329
     * Set user
330
     *
331
     * @param string $user
332
     *
333
     * @return Configuration
334
     */
335 4
    public function setUser($user)
336
    {
337 4
        $this->user = $user;
338
339 4
        return $this;
340
    }
341
342
    /**
343
     * Get name
344
     *
345
     * @return string
346
     */
347 21
    public function getName()
348
    {
349 21
        return $this->name;
350
    }
351
352
    /**
353
     * Set name
354
     *
355
     * @param string $name
356
     *
357
     * @return Configuration
358
     */
359 23
    public function setName($name)
360
    {
361 23
        $this->name = $name;
362
363 23
        return $this;
364
    }
365
366
    /**
367
     * Get pem file
368
     *
369
     * @return string
370
     */
371 1
    public function getPemFile()
372
    {
373 1
        return $this->pemFile;
374
    }
375
376
    /**
377
     * To auth with pem file use pemFile() method instead of this.
378
     *
379
     * @param string $pemFile
380
     *
381
     * @return Configuration
382
     */
383 1
    public function setPemFile($pemFile)
384
    {
385 1
        $this->pemFile = $this->parseHome($pemFile);
386
387 1
        return $this;
388
    }
389
390
    /**
391
     * Parse "~" symbol from path.
392
     *
393
     * @param string $path
394
     *
395
     * @return string
396
     */
397 2
    private function parseHome($path)
398
    {
399 2
        if (isset($_SERVER['HOME'])) {
400 2
            $path = str_replace('~', $_SERVER['HOME'], $path);
401 2
        } elseif (isset($_SERVER['HOMEDRIVE'], $_SERVER['HOMEPATH'])) {
402
            $path = str_replace('~', $_SERVER['HOMEDRIVE'] . $_SERVER['HOMEPATH'], $path);
403
        }
404
405 2
        return $path;
406
    }
407
408
    /**
409
     * Get real password
410
     *
411
     * @param mixed $password
412
     *
413
     * @return string
414
     */
415 3
    private function getRealPassword($password)
416
    {
417 3
        if ($password instanceof PasswordGetterInterface) {
418 2
            return $password->getPassword($this->getHost(), $this->getUser());
419
        }
420
421 1
        return $password;
422
    }
423
424
    /**
425
     * Set pty
426
     *
427
     * @param $pty
428
     */
429
    public function setPty($pty)
430
    {
431
        $this->pty = $pty;
432
    }
433
434
    /**
435
     * Get pty option
436
     *
437
     * @return mixed
438
     */
439
    public function getPty()
440
    {
441
        return $this->pty;
442
    }
443
444
    /**
445
     * Set pty for ssh2 connection. For retro compatibility
446
     *
447
     * @param $ssh2Pty
448
     * @deprecated
449
     */
450
    public function setSsh2Pty($ssh2Pty)
451
    {
452
        $this->setPty($ssh2Pty);
453
    }
454
455
    /**
456
     * Get pty option for ssh2 connection. For retro compatibility
457
     *
458
     * @deprecated
459
     * @return mixed
460
     */
461
    public function getSsh2Pty()
462
    {
463
        return $this->getPty();
464
    }
465
}
466