From e965feac0c11f9e4e99028503f8734818e220673 Mon Sep 17 00:00:00 2001 From: Yurii Myronchuk Date: Wed, 10 Apr 2024 16:22:36 +0000 Subject: [PATCH 1/3] Change type from to --- src/sale/Sale.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/sale/Sale.php b/src/sale/Sale.php index 81db5463..e4a4f77f 100755 --- a/src/sale/Sale.php +++ b/src/sale/Sale.php @@ -52,7 +52,7 @@ class Sale implements SaleInterface protected ?DateTimeImmutable $closeTime = null; - protected ?array $data = null; + protected mixed $data = null; public function __construct( $id, @@ -60,14 +60,14 @@ public function __construct( 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() @@ -129,6 +129,23 @@ public function setId($id) $this->id = $id; } + public function setData(mixed $data = null) + { + 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; From 619fb1e0ea264cf3369ec8f19b9882df6b9f846e Mon Sep 17 00:00:00 2001 From: Yurii Myronchuk Date: Wed, 10 Apr 2024 16:34:00 +0000 Subject: [PATCH 2/3] fix --- src/sale/Sale.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sale/Sale.php b/src/sale/Sale.php index e4a4f77f..8e26f01b 100755 --- a/src/sale/Sale.php +++ b/src/sale/Sale.php @@ -134,7 +134,7 @@ public function setData(mixed $data = null) if (is_null($data) || empty($data)) { return ; } - if ($is_string($data)) { + if (is_string($data)) { $this->data = json_decode($data, true, 512, JSON_THROW_ON_ERROR); return ; } From 5d8a30e7856328cda1909c8793865152295590d2 Mon Sep 17 00:00:00 2001 From: Yurii Myronchuk Date: Wed, 10 Apr 2024 20:37:43 +0000 Subject: [PATCH 3/3] add type hint --- src/sale/Sale.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/sale/Sale.php b/src/sale/Sale.php index 8e26f01b..cff506ce 100755 --- a/src/sale/Sale.php +++ b/src/sale/Sale.php @@ -75,27 +75,27 @@ 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; } @@ -118,7 +118,7 @@ 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; @@ -126,10 +126,11 @@ public function setId($id) if ($this->hasId()) { throw new CannotReassignException('sale id'); } + $this->id = $id; } - public function setData(mixed $data = null) + public function setData(mixed $data = null): void { if (is_null($data) || empty($data)) { return ;