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:45 queued 30s
created

Ssh::getCommand()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

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