Resize::getBody()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
ccs 5
cts 5
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 Resize extends Action
12
{
13
    /**
14
     * Action parameter
15
     *
16
     * @const ACTION
17
     */
18
    const ACTION = 'resize';
19
20
    /**
21
     * Action HTTP Method
22
     *
23
     * @const method
24
     */
25
    const METHOD = 'POST';
26
27
    /**
28
     * Size slug
29
     *
30
     * @var string size
31
     */
32
    protected $size;
33
34
    /**
35
     * Boolean to determine whether to increase disk size
36
     *
37
     * @var bool disk
38
     */
39
    protected $disk;
40
41
    /**
42
     * Constructor for the Resize Action
43
     *
44
     * @param Array $values
45
     */
46 10
    public function __construct(Array $values)
47
    {
48 10
        if (!isset($values['size'])) {
49 1
            throw new InvalidArgumentException('Required value "size" is not present');
50
        }
51
52 9
        if (!is_string($values['size'])) {
53 3
            throw new InvalidArgumentException('The size parameter must be a string (slug)');
54
        }
55
56 6
        if (isset($values['disk']) && !is_bool($values['disk'])) {
57 3
            throw new InvalidArgumentException('The disk parameter must be a boolean');
58
        }
59
60 3
        $this->size = $values['size'];
61 3
        $this->disk = (isset($values['disk'])) ? $values['disk'] : true;
62 3
    }
63
64
    /**
65
     * Return the body of the request
66
     *
67
     * @return string json representation of the body
68
     */
69 2
    public function getBody()
70
    {
71 2
        return json_encode([
72 2
            'type' => self::ACTION,
73 2
            'disk' => $this->disk,
74 2
            'size' => $this->size
75
        ]);
76
    }
77
}
78
79