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
Pull Request — master (#28)
by Ruben
01:26
created

Ssh   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 63
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getCommand() 0 16 1
A execute() 0 6 1
A getExtraOptions() 0 19 4
A wrapArray() 0 4 1
1
<?php
2
3
namespace Spatie\Ssh;
4
5
use Exception;
6
use Symfony\Component\Process\Process;
7
8
class Ssh
9
{
10
    use SecureConnection;
11
12
    /**
13
     * @param string|array $command
14
     *
15
     * @return string
16
     */
17
    public function getCommand($command): string
18
    {
19
        $commands = $this->wrapArray($command);
20
21
        $extraOptions = $this->getExtraOptions();
22
23
        $commandString = implode(PHP_EOL, $commands);
24
25
        $delimiter = 'EOF-SPATIE-SSH';
26
27
        $target = $this->getTarget();
28
29
        return "ssh {$extraOptions} {$target} 'bash -se' << \\$delimiter".PHP_EOL
30
            .$commandString.PHP_EOL
31
            .$delimiter;
32
    }
33
34
    /**
35
     * @param string|array $command
36
     *
37
     * @return \Symfony\Component\Process\Process
38
     */
39
    public function execute($command): Process
40
    {
41
        $sshCommand = $this->getCommand($command);
42
43
        return $this->run($sshCommand);
44
    }
45
46
    protected function getExtraOptions(): string
47
    {
48
        $extraOptions = [];
49
50
        if ($this->pathToPrivateKey) {
51
            $extraOptions[] = "-i {$this->pathToPrivateKey}";
52
        }
53
54
        if (! is_null($this->port)) {
55
            $extraOptions[] = "-p {$this->port}";
56
        }
57
58
        if (! $this->enableStrictHostChecking) {
59
            $extraOptions[] = '-o StrictHostKeyChecking=no';
60
            $extraOptions[] = '-o UserKnownHostsFile=/dev/null';
61
        }
62
63
        return implode(' ', $extraOptions);
64
    }
65
66
    protected function wrapArray($arrayOrString): array
67
    {
68
        return (array) $arrayOrString;
69
    }
70
}
71