RemoteTopCommand::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 3
crap 1
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 1
    public function __construct($sshString, $sshPort = null, $sshIdentityFile = null)
27
    {
28 1
        $this->sshString = $sshString;
29 1
        $this->sshIdentityFile = $sshIdentityFile;
30 1
        $this->sshPort = $sshPort;
31
32 1
        parent::__construct();
33 1
    }
34
35
36
    /**
37
     * @return Command
38
     */
39 1
    protected function buildCommand()
40
    {
41 1
        $command = new Command();
42
        $command
43 1
            ->setCommand('ssh')
44 1
            ->addArgument(new Argument($this->sshString));
45
46 1
        if (null !== $this->sshPort) {
47 1
            $command->addArgument(new Argument('-p', $this->sshPort));
48 1
        }
49
50 1
        if (null !== $this->sshIdentityFile) {
51
            $command->addArgument(new Argument('-i', $this->sshIdentityFile));
52
        }
53
54
        $command
55 1
            ->addArgument(new Argument('top', null, null, false))
56 1
            ->addArgument(new Argument('-b'))
57 1
            ->addArgument(new Argument('-n', 1));
58
59 1
        return $command;
60
    }
61
}