|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This software may be modified and distributed under the terms |
|
7
|
|
|
* of the MIT license. See the LICENSE file for details. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace FAPI\Sylius\Model\Product; |
|
11
|
|
|
|
|
12
|
|
|
use FAPI\Sylius\Model\CreatableFromArray; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @author Kasim Taskin <[email protected]> |
|
16
|
|
|
*/ |
|
17
|
|
|
final class Product implements CreatableFromArray |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var int |
|
21
|
|
|
*/ |
|
22
|
|
|
private $id = 0; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var null|string |
|
26
|
|
|
*/ |
|
27
|
|
|
private $name; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var null|string |
|
31
|
|
|
*/ |
|
32
|
|
|
private $code = ''; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var string[] |
|
36
|
|
|
*/ |
|
37
|
|
|
private $channels = []; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var string[][] |
|
41
|
|
|
*/ |
|
42
|
|
|
private $translations = []; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var Image[] |
|
46
|
|
|
*/ |
|
47
|
|
|
private $images = []; |
|
48
|
|
|
|
|
49
|
|
|
private function __construct() |
|
50
|
|
|
{ |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return Product |
|
55
|
|
|
*/ |
|
56
|
|
|
public static function createFromArray(array $data): self |
|
57
|
|
|
{ |
|
58
|
|
|
$model = new self(); |
|
59
|
|
|
if (isset($data['id'])) { |
|
60
|
|
|
$model->id = $data['id']; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
if (isset($data['code'])) { |
|
64
|
|
|
$model->code = $data['code']; |
|
65
|
|
|
} |
|
66
|
|
|
if (isset($data['name'])) { |
|
67
|
|
|
$model->name = $data['name']; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
if (isset($data['channels'])) { |
|
71
|
|
|
$model->channels = $data['channels']; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$translations = []; |
|
|
|
|
|
|
75
|
|
|
if (isset($data['translations'])) { |
|
76
|
|
|
$model->translations = $data['translations']; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
if (isset($data['images'])) { |
|
80
|
|
|
foreach ($data['images'] as $image) { |
|
81
|
|
|
$model->images[] = Image::createFromArray($image); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return $model; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function getId(): int |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->id; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function getCode(): string |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->code; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @return string[] |
|
100
|
|
|
*/ |
|
101
|
|
|
public function getChannels(): array |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->channels; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @return \string[][] |
|
108
|
|
|
*/ |
|
109
|
|
|
public function getTranslations(): array |
|
110
|
|
|
{ |
|
111
|
|
|
return $this->translations; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @return Image[] |
|
116
|
|
|
*/ |
|
117
|
|
|
public function getImages(): array |
|
118
|
|
|
{ |
|
119
|
|
|
return $this->images; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function getName(): ?string |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->name; |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.