Completed
Push — master ( 878182...082ba8 )
by Tyler
02:08
created

LinodeRebooter   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 36%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 1
cbo 3
dl 0
loc 72
ccs 9
cts 25
cp 0.36
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 9 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 3
    public function __construct($token, $linodeId, $host = "api.linode.com", Client $client = null){
22
23 3
        if(!$client instanceof Client){
24 3
            $client = new Client();
25 3
        }
26
27 3
        $this->client = $client;
28 3
        $this->token = $token;
29 3
        $this->linodeId = $linodeId;
30 3
        $this->host = $host;
31 3
    }
32
33
    /**
34
     * Executes a Boot command
35
     * @return asdfasdfkdkdkdkd
36
     */
37
    public function boot(){
38
        return $this->exec("linode.boot");
39
    }
40
41
    /**
42
     * Executes a Reboot command
43
     * @return asdfasdfkdkdkdkd
44
     */
45
    public function reboot(){
46
        return $this->exec("linode.reboot");
47
    }
48
49
    /**
50
     * Executes a Shutdown command
51
     * @return asdfasdfkdkdkdkd
52
     */
53
    public function shutdown(){
54
        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
    protected function buildRequestUrl($action){
63
        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 asdfasdfkdkdkdkd
69
     */
70
    protected function exec($action){
71
        $url = $this->buildRequestUrl($action);
72
        $res = $this->client->request('GET', $url);
73
74
        var_dump($url);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($url); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
75
        var_dump($res->getStatusCode());
76
        var_dump($res->getBody());
77
        var_dump(get_class($res));
78
    }
79
}