Skip to content

Commit

Permalink
Add Product::Name (#26)
Browse files Browse the repository at this point in the history
* Add name

* cs
  • Loading branch information
Nyholm authored Nov 30, 2018
1 parent f193ccd commit 9d4a83d
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions src/Model/Product/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,75 +19,70 @@ final class Product implements CreatableFromArray
/**
* @var int
*/
private $id;
private $id = 0;

/**
* @var string
* @var null|string
*/
private $code;
private $name;

/**
* @var null|string
*/
private $code = '';

/**
* @var string[]
*/
private $channels;
private $channels = [];

/**
* @var string[][]
*/
private $translations;
private $translations = [];

/**
* @var Image[]
*/
private $images;

private function __construct(
int $id,
string $code,
array $channels,
array $translations,
array $images
) {
$this->id = $id;
$this->code = $code;
$this->channels = $channels;
$this->translations = $translations;
$this->images = $images;
private $images = [];

private function __construct()
{
}

/**
* @return Product
*/
public static function createFromArray(array $data): self
{
$id = -1;
$model = new self();
if (isset($data['id'])) {
$id = $data['id'];
$model->id = $data['id'];
}

$code = '';
if (isset($data['code'])) {
$code = $data['code'];
$model->code = $data['code'];
}
if (isset($data['name'])) {
$model->name = $data['name'];
}

$channels = [];
if (isset($data['channels'])) {
$channels = $data['channels'];
$model->channels = $data['channels'];
}

$translations = [];
if (isset($data['translations'])) {
$translations = $data['translations'];
$model->translations = $data['translations'];
}

$images = [];
if (isset($data['images'])) {
foreach ($data['images'] as $image) {
$images[] = Image::createFromArray($image);
$model->images[] = Image::createFromArray($image);
}
}

return new self($id, $code, $channels, $translations, $images);
return $model;
}

public function getId(): int
Expand Down Expand Up @@ -123,4 +118,9 @@ public function getImages(): array
{
return $this->images;
}

public function getName(): ?string
{
return $this->name;
}
}

0 comments on commit 9d4a83d

Please sign in to comment.