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
|
2 |
|
public function getId(): ? string |
24
|
|
|
{ |
25
|
2 |
|
return $this->id; |
26
|
|
|
} |
27
|
|
|
|
28
|
2 |
|
public function getType(): ? string |
29
|
|
|
{ |
30
|
2 |
|
return $this->type; |
31
|
|
|
} |
32
|
|
|
|
33
|
3 |
|
public function getValue(): ? string |
34
|
|
|
{ |
35
|
3 |
|
return $this->value; |
36
|
|
|
} |
37
|
|
|
|
38
|
2 |
|
public function getAutoIncrement(): ? bool |
39
|
|
|
{ |
40
|
2 |
|
return $this->auto_increment; |
41
|
|
|
} |
42
|
|
|
|
43
|
2 |
|
public function getPadDirection(): ? string |
44
|
|
|
{ |
45
|
2 |
|
return $this->pad_direction; |
46
|
|
|
} |
47
|
|
|
|
48
|
2 |
|
public function getPadChar(): ? string |
49
|
|
|
{ |
50
|
2 |
|
return $this->pad_char; |
51
|
|
|
} |
52
|
|
|
|
53
|
2 |
|
public function getPadLength(): ? int |
54
|
|
|
{ |
55
|
2 |
|
return $this->pad_length; |
56
|
|
|
} |
57
|
|
|
|
58
|
4 |
|
public function reset(array $data = null) |
59
|
|
|
{ |
60
|
4 |
|
if ($data) { |
61
|
4 |
|
foreach ($data as $key => $value) { |
62
|
|
|
switch ($key) { |
63
|
4 |
|
case 'id': |
|
|
|
|
64
|
4 |
|
$this->id = $value; |
65
|
4 |
|
break; |
66
|
4 |
|
case 'type': |
67
|
4 |
|
$this->type = $value; |
68
|
4 |
|
break; |
69
|
4 |
|
case 'value': |
70
|
4 |
|
$this->value = $value; |
71
|
4 |
|
break; |
72
|
4 |
|
case 'auto_increment': |
73
|
4 |
|
$this->auto_increment = $value; |
74
|
4 |
|
break; |
75
|
4 |
|
case 'pad_direction': |
76
|
4 |
|
$this->pad_direction = $value; |
77
|
4 |
|
break; |
78
|
4 |
|
case 'pad_char': |
79
|
4 |
|
$this->pad_char = $value; |
80
|
4 |
|
break; |
81
|
4 |
|
case 'pad_length': |
82
|
4 |
|
$this->pad_length = $value; |
83
|
4 |
|
break; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
} |
87
|
4 |
|
} |
88
|
|
|
|
89
|
1 |
|
public function setType(string $type) |
90
|
|
|
{ |
91
|
1 |
|
$this->type = $type; |
92
|
1 |
|
} |
93
|
|
|
|
94
|
2 |
|
public function setValue(string $value = null) |
95
|
|
|
{ |
96
|
2 |
|
$this->value = $value; |
97
|
2 |
|
} |
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
|
2 |
|
public function jsonSerialize(): array |
120
|
|
|
{ |
121
|
|
|
$returnValue = [ |
122
|
2 |
|
'type' => $this->getType(), |
123
|
2 |
|
'value' => $this->getValue(), |
124
|
2 |
|
'auto_increment' => $this->getAutoIncrement(), |
125
|
2 |
|
'pad_direction' => $this->getPadDirection(), |
126
|
2 |
|
'pad_char' => $this->getPadChar(), |
127
|
2 |
|
'pad_length' => $this->getPadLength(), |
128
|
|
|
]; |
129
|
2 |
|
if ($this->getId()) { |
130
|
1 |
|
$returnValue = array_merge(['id' => $this->getId()], $returnValue); |
131
|
|
|
} |
132
|
2 |
|
return $returnValue; |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
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.
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.