Completed
Push — master ( 0190e6...eed21f )
by Tyler
495:46 queued 493:37
created

SshRebooter::setSession()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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