Completed
Branch master (ae6db9)
by Matt
01:40
created

Restore::getBody()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Billow\Actions;
3
use InvalidArgumentException;
4
5
/**
6
 * @author Matt Frost<[email protected]>
7
 * @package Billow
8
 * @subpackage Actions
9
 * @license http://opensource.org/licenses/MIT MIT
10
 */
11
class Restore extends Action
12
{
13
    /**
14
     * Action parameter
15
     *
16
     * @const ACTION
17
     */
18
    const ACTION = 'enable_backups';
19
20
    /**
21
     * Action HTTP Method
22
     *
23
     * @const method
24
     */
25
    const METHOD = 'POST';
26
27
    /**
28
     * Image ID
29
     *
30
     * @var int $image
31
     */
32
    protected $image;
33
34
    /**
35
     * Constructor for Restore Action
36
     *
37
     * @param Array $values 
38
     */
39 5
    public function __construct(Array $values)
40
    {
41 5
        if (!isset($values['image'])) {
42 1
            throw new InvalidArgumentException('Require value "image" is not present');
43
        }
44
45 4
        if (!is_numeric($values['image']) && !is_string($values['image'])) {
46 1
            throw new InvalidArgumentException('Image parameter must be an ID or a string');
47
        }
48
49 3
        $this->image = $values['image'];
50 3
    }
51
52
    /**
53
     * Return the body of the request
54
     *
55
     * @return string json representation of the body
56
     */
57 2
    public function getBody()
58
    {
59 2
        return json_encode([
60 2
            'type' => self::ACTION,
61 2
            'image' => $this->image
62
        ]);
63
    }
64
}
65