Action::setId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Billow\Actions;
3
use GuzzleHttp\Psr7\Request;
4
use GuzzleHttp\Psr7\Stream;
5
use RuntimeException;
6
7
/**
8
 * @author Matt Frost<[email protected]>
9
 * @package Billow
10
 * @subpackage Actions
11
 * @license http://opensource.org/licenses/MIT MIT
12
 */
13
abstract class Action implements ActionInterface
14
{
15
    /**
16
     * Endpoint for the action
17
     *
18
     * @const ENDPOINT
19
     */
20
    const ENDPOINT = 'https://api.digitalocean.com/v2/droplets/[:id:]/actions';
21
22
    /**
23
     * HTTP Method
24
     *
25
     * @const METHOD
26
     */
27
    const METHOD = 'POST';
28
29
    /**
30
     * ID of the droplet to perform the action on
31
     *
32
     * @var mixed $id
33
     */
34
    protected $id;
35
36
    /**
37
     * Set the droplet id
38
     *
39
     * @param mixed $id
40
     */
41 22
    public function setId($id)
42
    {
43 22
       $this->id = $id; 
44 22
    }
45
46
    /**
47
     * Method to return the action request object
48
     *
49
     * @param Array $headers
50
     * @param string $body
51
     * @return \GuzzleHttp\Psr7\Request
52
     */
53 39
    public function getRequest(Array $headers = [], $body = '')
54
    {
55 39
        if ($this->id === null) {
56 18
            throw new RuntimeException('You must provide the Droplet ID you want to perform an action on');
57
        }
58
59 21
        if (method_exists($this, 'getBody') && $body === '') {
60 20
            $body = $this->getBody();
61
        }
62
63 21
        $endpoint = str_replace('[:id:]', $this->id, self::ENDPOINT);
64
65 21
        return new Request(
66 21
            static::METHOD,
67 21
            $endpoint,
68 21
            $headers,
69 21
            $body
70
        );
71
    }
72
}
73