Skip to content

Change type data from array to mixed #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions src/sale/Sale.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,50 +52,50 @@ class Sale implements SaleInterface

protected ?DateTimeImmutable $closeTime = null;

protected ?array $data = null;
protected mixed $data = null;

public function __construct(
$id,
TargetInterface $target,
CustomerInterface $customer,
?PlanInterface $plan = null,
?DateTimeImmutable $time = null,
?array $data = null,
mixed $data = null,
) {
$this->id = $id;
$this->target = $target;
$this->customer = $customer;
$this->plan = $plan;
$this->time = $time ?? new DateTimeImmutable();
$this->data = $data;
$this->data = $this->setData($data);
}

public function getId()
{
return $this->id;
}

public function getTarget()
public function getTarget(): TargetInterface
{
return $this->target;
}

public function getCustomer()
public function getCustomer(): CustomerInterface
{
return $this->customer;
}

public function getPlan()
public function getPlan(): ?PlanInterface
{
return $this->plan;
}

public function getTime()
public function getTime(): ?DateTimeImmutable
{
return $this->time;
}

public function hasId()
public function hasId(): bool
{
return $this->id !== null;
}
Expand All @@ -118,17 +118,35 @@ public function close(DateTimeImmutable $closeTime): void
$this->closeTime = $closeTime;
}

public function setId($id)
public function setId($id): void
{
if ((string) $this->id === (string) $id) {
return;
}
if ($this->hasId()) {
throw new CannotReassignException('sale id');
}

$this->id = $id;
}

public function setData(mixed $data = null): void
{
if (is_null($data) || empty($data)) {
return ;
}
if (is_string($data)) {
$this->data = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
return ;
}

if (is_object($data)) {
$this->data = json_decode(json_encode($data), true, 512, JSON_THROW_ON_ERROR);
}

$this->data = $data;
}

public function getData()
{
return $this->data;
Expand Down