Skip to content

Commit 9d4a83d

Browse files
authored
Add Product::Name (#26)
* Add name * cs
1 parent f193ccd commit 9d4a83d

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

src/Model/Product/Product.php

+29-29
Original file line numberDiff line numberDiff line change
@@ -19,75 +19,70 @@ final class Product implements CreatableFromArray
1919
/**
2020
* @var int
2121
*/
22-
private $id;
22+
private $id = 0;
2323

2424
/**
25-
* @var string
25+
* @var null|string
2626
*/
27-
private $code;
27+
private $name;
28+
29+
/**
30+
* @var null|string
31+
*/
32+
private $code = '';
2833

2934
/**
3035
* @var string[]
3136
*/
32-
private $channels;
37+
private $channels = [];
3338

3439
/**
3540
* @var string[][]
3641
*/
37-
private $translations;
42+
private $translations = [];
3843

3944
/**
4045
* @var Image[]
4146
*/
42-
private $images;
43-
44-
private function __construct(
45-
int $id,
46-
string $code,
47-
array $channels,
48-
array $translations,
49-
array $images
50-
) {
51-
$this->id = $id;
52-
$this->code = $code;
53-
$this->channels = $channels;
54-
$this->translations = $translations;
55-
$this->images = $images;
47+
private $images = [];
48+
49+
private function __construct()
50+
{
5651
}
5752

5853
/**
5954
* @return Product
6055
*/
6156
public static function createFromArray(array $data): self
6257
{
63-
$id = -1;
58+
$model = new self();
6459
if (isset($data['id'])) {
65-
$id = $data['id'];
60+
$model->id = $data['id'];
6661
}
6762

68-
$code = '';
6963
if (isset($data['code'])) {
70-
$code = $data['code'];
64+
$model->code = $data['code'];
65+
}
66+
if (isset($data['name'])) {
67+
$model->name = $data['name'];
7168
}
7269

73-
$channels = [];
7470
if (isset($data['channels'])) {
75-
$channels = $data['channels'];
71+
$model->channels = $data['channels'];
7672
}
7773

7874
$translations = [];
7975
if (isset($data['translations'])) {
80-
$translations = $data['translations'];
76+
$model->translations = $data['translations'];
8177
}
8278

83-
$images = [];
8479
if (isset($data['images'])) {
8580
foreach ($data['images'] as $image) {
86-
$images[] = Image::createFromArray($image);
81+
$model->images[] = Image::createFromArray($image);
8782
}
8883
}
8984

90-
return new self($id, $code, $channels, $translations, $images);
85+
return $model;
9186
}
9287

9388
public function getId(): int
@@ -123,4 +118,9 @@ public function getImages(): array
123118
{
124119
return $this->images;
125120
}
121+
122+
public function getName(): ?string
123+
{
124+
return $this->name;
125+
}
126126
}

0 commit comments

Comments
 (0)