Completed
Push — master ( 7c71a4...34aff4 )
by Matt
05:48
created

Rebuild   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 91.67%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 1
dl 54
loc 54
ccs 11
cts 12
cp 0.9167
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 11 11 4
A getBody() 7 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 Rebuild 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 = 'rebuild';
19
20
    /**
21
     * Action HTTP Method
22
     *
23
     * @const method
24
     */
25
    const METHOD = 'POST';
26
27
    /**
28
     * Image slug or ID
29
     *
30
     * @var mixed image
31
     */
32
    protected $image;
33
34
    /**
35
     * Constructor for rebuild action
36
     *
37
     * @param Array values
38
     * @throws \InvalidArgumentException
39
     */
40 7
    public function __construct(Array $values)
41
    {
42 7
        if (!isset($values['image'])) {
43 4
            throw new InvalidArgumentException('Required value "image" is not present');
44
        }
45
46 3
        if (!is_numeric($values['image']) && !is_string($values['image'])) {
47
            throw new InvalidArgumentException("Image argument must be a slug or ID");
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 2
        ]);
63
    }
64
}
65
66