Ssh   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 63
ccs 17
cts 17
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getExec() 0 3 1
A boot() 0 3 1
A reboot() 0 4 1
A shutdown() 0 4 1
A getSession() 0 4 1
A setSession() 0 5 1
1
<?php
2
3
namespace Tylercd100\Rebooter\Drivers\Ssh;
4
5
use Ssh\Session;
6
use Tylercd100\Rebooter\Drivers\ServerController;
7
use Tylercd100\Rebooter\Exceptions\MethodNotAllowedException;
8
9
abstract class Ssh implements ServerController
10
{
11
    /**
12
     * @var Session
13
     */
14
    protected $session;
15
16
    /**
17
     * Gets the SSH session executor
18
     * @return \Ssh\Exec
19
     */
20 3
    public function getExec() {
21 3
        return $this->session->getExec();
22
    }
23
24
    /**
25
     * Throws an Exception because you cannot boot a powered down machine from ssh
26
     * @return void
27
     */
28 3
    public function boot() {
29 3
        throw new MethodNotAllowedException("You cannot use SSH to boot a powered down server.");
30
    }
31
32
    /**
33
     * Executes a Reboot command
34
     * @return void
35
     */
36 3
    public function reboot() {
37 3
        $exec = $this->getExec();
38 3
        $exec->run('reboot');
39 3
    }
40
41
    /**
42
     * Executes a Shutdown command
43
     * @return void
44
     */
45 3
    public function shutdown() {
46 3
        $exec = $this->getExec();
47 3
        $exec->run('shutdown -P now');
48 3
    }
49
50
    /**
51
     * Gets the value of session.
52
     *
53
     * @return Session
54
     */
55 3
    public function getSession()
56
    {
57 3
        return $this->session;
58
    }
59
60
    /**
61
     * Sets the value of session.
62
     *
63
     * @param Session $session the session
64
     * @return self
65
     */
66 6
    public function setSession(Session $session)
67
    {
68 6
        $this->session = $session;
69 6
        return $this;
70
    }
71
}