1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Waredesk\Models\Product\Variant; |
4
|
|
|
|
5
|
|
|
use DateTime; |
6
|
|
|
use JsonSerializable; |
7
|
|
|
use Waredesk\Collections\Products\Variants\Codes\Elements; |
8
|
|
|
use Waredesk\Entity; |
9
|
|
|
|
10
|
|
|
class Code implements Entity, JsonSerializable |
11
|
|
|
{ |
12
|
|
|
private $code; |
13
|
|
|
private $name; |
14
|
|
|
private $quantity; |
15
|
|
|
private $elements; |
16
|
|
|
private $creation; |
17
|
|
|
private $modification; |
18
|
|
|
|
19
|
|
|
public function __construct() |
20
|
|
|
{ |
21
|
|
|
$this->elements = new Elements(); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function __clone() |
25
|
|
|
{ |
26
|
|
|
$this->elements = clone $this->elements; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function getCode(): ? string |
30
|
|
|
{ |
31
|
|
|
return $this->code; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function getName(): ? string |
35
|
|
|
{ |
36
|
|
|
return $this->name; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function getQuantity(): ? int |
40
|
|
|
{ |
41
|
|
|
return $this->quantity; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getElements(): ? Elements |
45
|
|
|
{ |
46
|
|
|
return $this->elements; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function getCreation(): ? DateTime |
50
|
|
|
{ |
51
|
|
|
return $this->creation; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getModification(): ? DateTime |
55
|
|
|
{ |
56
|
|
|
return $this->modification; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function reset(array $data = null) |
60
|
|
|
{ |
61
|
|
|
if ($data) { |
62
|
|
|
foreach ($data as $key => $value) { |
63
|
|
|
switch ($key) { |
64
|
|
|
case 'code': |
|
|
|
|
65
|
|
|
$this->code = $value; |
66
|
|
|
break; |
67
|
|
|
case 'name': |
68
|
|
|
$this->name = $value; |
69
|
|
|
break; |
70
|
|
|
case 'quantity': |
71
|
|
|
$this->quantity = $value; |
72
|
|
|
break; |
73
|
|
|
case 'elements': |
74
|
|
|
$this->elements = $value; |
75
|
|
|
break; |
76
|
|
|
case 'creation': |
77
|
|
|
$this->creation = $value; |
78
|
|
|
break; |
79
|
|
|
case 'modification': |
80
|
|
|
$this->modification = $value; |
81
|
|
|
break; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function setCode(string $code) |
88
|
|
|
{ |
89
|
|
|
$this->code = $code; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function setQuantity(int $quantity = null) |
93
|
|
|
{ |
94
|
|
|
$this->quantity = $quantity; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function jsonSerialize(): array |
98
|
|
|
{ |
99
|
|
|
return [ |
100
|
|
|
'code' => $this->getCode(), |
101
|
|
|
'quantity' => $this->getQuantity(), |
102
|
|
|
'elements' => $this->getElements()->jsonSerialize(), |
103
|
|
|
]; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
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.