From 51b70fe5accfed6290e7be867659098504e391ac Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Fri, 26 Jan 2024 17:38:38 +0100 Subject: [PATCH 1/3] feat: allow un/serialize for currency --- src/Currency.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Currency.php b/src/Currency.php index f0505481..733e6902 100644 --- a/src/Currency.php +++ b/src/Currency.php @@ -57,4 +57,17 @@ public function jsonSerialize(): string { return $this->code; } + + /** + * @return array + */ + public function __serialize(): array + { + return ['code' => $this->code]; + } + + public function __unserialize(array $data): void + { + $this->code = (string) $data['code']; + } } From 18993f44bfd055aaedd504a6af552fb49131057b Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Fri, 26 Jan 2024 18:02:20 +0100 Subject: [PATCH 2/3] feat: allow un/serialize for currency --- src/Currency.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Currency.php b/src/Currency.php index 733e6902..3e20cba4 100644 --- a/src/Currency.php +++ b/src/Currency.php @@ -5,6 +5,7 @@ namespace Money; use JsonSerializable; +use Serializable; use function strtoupper; @@ -15,7 +16,7 @@ * * @psalm-immutable */ -final class Currency implements JsonSerializable +final class Currency implements JsonSerializable, Serializable { /** * Currency code. @@ -66,8 +67,23 @@ public function __serialize(): array return ['code' => $this->code]; } + # TODO Correct PSALM? public function __unserialize(array $data): void { $this->code = (string) $data['code']; } + + /** + * @return array + */ + public function serialize(): array + { + return $this->__serialize(); + } + + # TODO Correct PSALM? + public function unserialize(string $data) + { + return $this->__unserialize($data); + } } From baafdd24d996b764bd1dc15df5e83dec63625dfb Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Fri, 26 Jan 2024 18:06:00 +0100 Subject: [PATCH 3/3] feat: allow un/serialize for currency --- src/Currency.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Currency.php b/src/Currency.php index 3e20cba4..3e3380c6 100644 --- a/src/Currency.php +++ b/src/Currency.php @@ -67,7 +67,7 @@ public function __serialize(): array return ['code' => $this->code]; } - # TODO Correct PSALM? + // TODO Correct PSALM? public function __unserialize(array $data): void { $this->code = (string) $data['code']; @@ -81,9 +81,10 @@ public function serialize(): array return $this->__serialize(); } - # TODO Correct PSALM? - public function unserialize(string $data) + // TODO Correct PSALM? + // Correct CODE? + public function unserialize(string $data): void { - return $this->__unserialize($data); + $this->__unserialize((array) $data); } }