Completed
Push — master ( 4e457c...e6ff17 )
by Gabriel
02:37
created

Element::reset()   D

Complexity

Conditions 10
Paths 10

Size

Total Lines 30
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 25
CRAP Score 10

Importance

Changes 0
Metric Value
dl 0
loc 30
ccs 25
cts 25
cp 1
rs 4.8196
c 0
b 0
f 0
cc 10
eloc 25
nc 10
nop 1
crap 10

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Waredesk\Models\Code;
4
5
use DateTime;
6
use JsonSerializable;
7
use Waredesk\Collections\Products\Variants\Annotations;
8
use Waredesk\Collections\Products\Variants\Codes;
9
use Waredesk\Collections\Products\Variants\Prices;
10
use Waredesk\Entity;
11
use Waredesk\Image;
12
use Waredesk\ReplaceableEntity;
13
14
class Element implements Entity, ReplaceableEntity, JsonSerializable
15
{
16
    private $id;
17
    private $type;
18
    private $value;
19
    private $auto_increment;
20
    private $pad_direction;
21
    private $pad_char;
22
    private $pad_length;
23
24 1
    public function __clone()
25
    {
26 1
    }
27
28 1
    public function getId(): ? string
29
    {
30 1
        return $this->id;
31
    }
32
33 1
    public function getType(): ? string
34
    {
35 1
        return $this->type;
36
    }
37
38 2
    public function getValue(): ? string
39
    {
40 2
        return $this->value;
41
    }
42
43 1
    public function getAutoIncrement(): ? bool
44
    {
45 1
        return $this->auto_increment;
46
    }
47
48 1
    public function getPadDirection(): ? string
49
    {
50 1
        return $this->pad_direction;
51
    }
52
53 1
    public function getPadChar(): ? string
54
    {
55 1
        return $this->pad_char;
56
    }
57
58 1
    public function getPadLength(): ? int
59
    {
60 1
        return $this->pad_length;
61
    }
62
63 2
    public function reset(array $data = null)
64
    {
65 2
        if ($data) {
66 2
            foreach ($data as $key => $value) {
67
                switch ($key) {
68 2
                    case 'id':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
69 2
                        $this->id = $value;
70 2
                        break;
71 2
                    case 'type':
72 2
                        $this->type = $value;
73 2
                        break;
74 2
                    case 'value':
75 2
                        $this->value = $value;
76 2
                        break;
77 2
                    case 'auto_increment':
78 2
                        $this->auto_increment = $value;
79 2
                        break;
80 2
                    case 'pad_direction':
81 2
                        $this->pad_direction = $value;
82 2
                        break;
83 2
                    case 'pad_char':
84 2
                        $this->pad_char = $value;
85 2
                        break;
86 2
                    case 'pad_length':
87 2
                        $this->pad_length = $value;
88 2
                        break;
89
                }
90
            }
91
        }
92 2
    }
93
94 1
    public function setType(string $type)
95
    {
96 1
        $this->type = $type;
97 1
    }
98
99 1
    public function setValue(string $value = null)
100
    {
101 1
        $this->value = $value;
102 1
    }
103
104
    public function setAutoIncrement(bool $auto_increment = null)
105
    {
106
        $this->auto_increment = $auto_increment;
107
    }
108
109
    public function setPadDirection(string $pad_direction = null)
110
    {
111
        $this->pad_direction = $pad_direction;
112
    }
113
114
    public function setPadChar(string $pad_char = null)
115
    {
116
        $this->pad_char = $pad_char;
117
    }
118
119
    public function setPadLength(int $pad_length = null)
120
    {
121
        $this->pad_length = $pad_length;
122
    }
123
124 1
    public function jsonSerialize()
125
    {
126
        return [
127 1
            'type' => $this->getType(),
128 1
            'value' => $this->getValue(),
129 1
            'auto_increment' => $this->getAutoIncrement(),
130 1
            'pad_direction' => $this->getPadDirection(),
131 1
            'pad_char' => $this->getPadChar(),
132 1
            'pad_length' => $this->getPadLength(),
133
        ];
134
    }
135
}
136