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

CreateSnapshot   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 52
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 3
A getBody() 0 5 1
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 CreateSnapshot extends Action
12
{
13
    /**
14
     * Action parameter
15
     *
16
     * @const ACTION
17
     */
18
    const ACTION = 'snapshot';
19
20
    /**
21
     * Action HTTP Method
22
     *
23
     * @const method
24
     */
25
    const METHOD = 'POST';
26
27
    /**
28
     * Name of the snapshot to be created
29
     *
30
     * @var string name
31
     */
32
    private $name;
33
34
    /**
35
     * Constructor for the create snapshot action
36
     *
37
     * @param Array $values
38
     * @throws \InvalidArgumentException
39
     */
40 7
    public function __construct(Array $values)
41
    {
42 7
        if (!isset($values['name'])) {
43 1
            throw new InvalidArgumentException('Required value "Name" is not present');
44
        }
45
46 6
        if (!is_string($values['name'])) {
47 4
            throw new InvalidArgumentException('Name parameter must be a string');
48
        }
49
50 2
        $this->name = $values['name'];
51 2
    }
52
53
    /**
54
     * Return the body of the request
55
     *
56
     * @return string json representation of the body
57
     */
58 1
    public function getBody()
59
    {
60 1
        return json_encode([
61 1
            'type' => self::ACTION,
62 1
            'name' => $this->name
63
        ]);
64
    }
65
}
66
67