Passed
Push — master ( 1fa5c8...3c4917 )
by Gabriel
02:55
created

Element::setValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 3
cts 3
cp 1
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Waredesk\Models\Variable;
4
5
use JsonSerializable;
6
use Waredesk\Entity;
7
use Waredesk\ReplaceableEntity;
8
9
class Element implements Entity, ReplaceableEntity, JsonSerializable
10
{
11
    private $id;
12
    private $type;
13
    private $value;
14
    private $auto_increment;
15
    private $pad_direction;
16
    private $pad_char;
17
    private $pad_length;
18
19 1
    public function __clone()
20
    {
21 1
    }
22
23 1
    public function getId(): ? string
24
    {
25 1
        return $this->id;
26
    }
27
28 1
    public function getType(): ? string
29
    {
30 1
        return $this->type;
31
    }
32
33 2
    public function getValue(): ? string
34
    {
35 2
        return $this->value;
36
    }
37
38 1
    public function getAutoIncrement(): ? bool
39
    {
40 1
        return $this->auto_increment;
41
    }
42
43 1
    public function getPadDirection(): ? string
44
    {
45 1
        return $this->pad_direction;
46
    }
47
48 1
    public function getPadChar(): ? string
49
    {
50 1
        return $this->pad_char;
51
    }
52
53 1
    public function getPadLength(): ? int
54
    {
55 1
        return $this->pad_length;
56
    }
57
58 2
    public function reset(array $data = null)
59
    {
60 2
        if ($data) {
61 2
            foreach ($data as $key => $value) {
62
                switch ($key) {
63 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...
64 2
                        $this->id = $value;
65 2
                        break;
66 2
                    case 'type':
67 2
                        $this->type = $value;
68 2
                        break;
69 2
                    case 'value':
70 2
                        $this->value = $value;
71 2
                        break;
72 2
                    case 'auto_increment':
73 2
                        $this->auto_increment = $value;
74 2
                        break;
75 2
                    case 'pad_direction':
76 2
                        $this->pad_direction = $value;
77 2
                        break;
78 2
                    case 'pad_char':
79 2
                        $this->pad_char = $value;
80 2
                        break;
81 2
                    case 'pad_length':
82 2
                        $this->pad_length = $value;
83 2
                        break;
84
                }
85
            }
86
        }
87 2
    }
88
89 1
    public function setType(string $type)
90
    {
91 1
        $this->type = $type;
92 1
    }
93
94 1
    public function setValue(string $value = null)
95
    {
96 1
        $this->value = $value;
97 1
    }
98
99
    public function setAutoIncrement(bool $auto_increment = null)
100
    {
101
        $this->auto_increment = $auto_increment;
102
    }
103
104
    public function setPadDirection(string $pad_direction = null)
105
    {
106
        $this->pad_direction = $pad_direction;
107
    }
108
109
    public function setPadChar(string $pad_char = null)
110
    {
111
        $this->pad_char = $pad_char;
112
    }
113
114
    public function setPadLength(int $pad_length = null)
115
    {
116
        $this->pad_length = $pad_length;
117
    }
118
119 1
    public function jsonSerialize(): array
120
    {
121
        $returnValue = [
122 1
            'type' => $this->getType(),
123 1
            'value' => $this->getValue(),
124 1
            'auto_increment' => $this->getAutoIncrement(),
125 1
            'pad_direction' => $this->getPadDirection(),
126 1
            'pad_char' => $this->getPadChar(),
127 1
            'pad_length' => $this->getPadLength(),
128
        ];
129 1
        if ($this->getId()) {
130
            $returnValue = array_merge(['id' => $this->getId()], $returnValue);
131
        }
132 1
        return $returnValue;
133
    }
134
}
135