Completed
Push — master ( 33d1c7...a9495c )
by Petrică
02:29
created

RemoteTopCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 3
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Petrica
5
 * Date: 5/29/2016
6
 * Time: 16:35
7
 */
8
namespace Petrica\StatsdSystem\Model;
9
10
use Tivie\Command\Argument;
11
use Tivie\Command\Command;
12
13
class RemoteTopCommand extends TopCommand
14
{
15
    /**
16
     * like user@ip
17
     *
18
     * @var string
19
     */
20
    private $sshString;
21
22
    private $sshIdentityFile;
23
24
    private $sshPort;
25
26
    public function __construct($sshString, $sshPort = null, $sshIdentityFile = null)
27
    {
28
        $this->sshString = $sshString;
29
        $this->sshIdentityFile = $sshIdentityFile;
30
        $this->sshPort = $sshPort;
31
32
        parent::__construct();
33
    }
34
35
36
    /**
37
     * @return Command
38
     */
39
    protected function buildCommand()
40
    {
41
        $command = new Command();
42
        $command
43
            ->setCommand('ssh')
44
            ->addArgument(new Argument($this->sshString));
45
46
        if (null !== $this->sshPort) {
47
            $command->addArgument(new Argument('-p', $this->sshPort));
48
        }
49
50
        if (null !== $this->sshIdentityFile) {
51
            $command->addArgument(new Argument('-i', $this->sshIdentityFile));
52
        }
53
54
        $command
55
            ->addArgument(new Argument('top', null, null, false))
56
            ->addArgument(new Argument('-b'))
57
            ->addArgument(new Argument('-n', 1));
58
59
        return $command;
60
    }
61
}