Passed
Push — master ( 534b0c...8bd354 )
by Matt
05:44
created

ChangeKernel::getBody()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 7
loc 7
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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 View Code Duplication
class ChangeKernel extends Action
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
12
{
13
    /**
14
     * Action parameter
15
     *
16
     * @const ACTION
17
     */
18
    const ACTION = 'change_kernel';
19
20
    /**
21
     * Action HTTP Method
22
     *
23
     * @const method
24
     */
25
    const METHOD = 'POST';
26
27
    /**
28
     * Unique number used to identify a specific kernel
29
     *
30
     * @var int kernel
31
     */
32
    protected $kernel;
33
34
    /**
35
     * Constructor for change kernel action
36
     *
37
     * @param array values
38
     * @throws \InvalidArgumentException
39
     */
40
    public function __construct(Array $values)
41
    {
42
        if (!isset($values['kernel'])) {
43
            throw new InvalidArgumentException('Kernel argument must be an integer');
44
        }
45
46
        if (!is_int($values['kernel'])) {
47
            throw new InvalidArgumentException('Required value "kernel" is not present');
48
        }
49
50
        $this->kernel = $values['kernel'];
51
    }
52
53
    /**
54
     * Return the body of the request
55
     *
56
     * @return string json representation of the body
57
     */
58
    public function getBody()
59
    {
60
        return json_encode([
61
            'type' => self::ACTION,
62
            'kernel' => $this->kernel
63
        ]);
64
    }
65
}
66
67