Completed
Push — master ( f72045...c6c2e9 )
by Tyler
02:09
created

LinodeRebooter   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 7
c 3
b 1
f 0
lcom 1
cbo 2
dl 0
loc 67
ccs 20
cts 20
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A boot() 0 3 1
A reboot() 0 3 1
A shutdown() 0 3 1
A buildRequestUrl() 0 3 1
A exec() 0 4 1
1
<?php
2
3
namespace Tylercd100\Rebooter\Api;
4
5
use GuzzleHttp\Client;
6
use Tylercd100\Rebooter\ApiRebooter;
7
8
class LinodeRebooter extends ApiRebooter {
9
10
    protected $token;
11
    protected $linodeId;
12
    protected $host;
13
    protected $client;
14
    
15
    /**
16
     * @param string $token    API Token from Linode.com
17
     * @param [type] $linodeId The ID of the linode you want to control
0 ignored issues
show
Documentation introduced by
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
18
     * @param string $host     The api host
19
     * @param Client $client   The guzzle client to use
20
     */
21 12
    public function __construct($token, $linodeId, $host = "api.linode.com", Client $client = null){
22
23 12
        if(!$client instanceof Client){
24 9
            $client = new Client();
25 9
        }
26
27 12
        $this->client = $client;
28 12
        $this->token = $token;
29 12
        $this->linodeId = $linodeId;
30 12
        $this->host = $host;
31 12
    }
32
33
    /**
34
     * Executes a Boot command
35
     * @return GuzzleHttp\Psr7\Response
36
     */
37 3
    public function boot(){
38 3
        return $this->exec("linode.boot");
39
    }
40
41
    /**
42
     * Executes a Reboot command
43
     * @return GuzzleHttp\Psr7\Response
44
     */
45 6
    public function reboot(){
46 6
        return $this->exec("linode.reboot");
47
    }
48
49
    /**
50
     * Executes a Shutdown command
51
     * @return GuzzleHttp\Psr7\Response
52
     */
53 3
    public function shutdown(){
54 3
        return $this->exec("linode.shutdown");
55
    }
56
57
    /**
58
     * Builds the request URL for the API call
59
     * @param  string $action The Linode API action
60
     * @return string
61
     */
62 6
    protected function buildRequestUrl($action){
63 6
        return "https://{$this->host}/?api_key={$this->token}&api_action={$action}&LinodeID={$this->linodeId}";
64
    }
65
66
    /**
67
     * Executes a command on the API
68
     * @return GuzzleHttp\Psr7\Response
69
     */
70 3
    protected function exec($action){
71 3
        $url = $this->buildRequestUrl($action);
72 3
        return $res = $this->client->request('GET', $url);
0 ignored issues
show
Unused Code introduced by
$res is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
73
    }
74
}