Completed
Push — master ( 434411...5e8f86 )
by Tyler
05:44
created

SshRebooter::getSession()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 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 SshRebooter 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
}