From 8479c0cf65100108bbb2eb869443233d9f19ddcd Mon Sep 17 00:00:00 2001 From: Pawel Trauth Date: Thu, 7 Nov 2019 10:02:07 +0000 Subject: [PATCH 1/2] fix: set metadata to [] if original event has it null to prevent type exception on getMetadata() call --- src/Console/Commands/EventStoreWorker.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/Commands/EventStoreWorker.php b/src/Console/Commands/EventStoreWorker.php index d971097..e9ab9b4 100644 --- a/src/Console/Commands/EventStoreWorker.php +++ b/src/Console/Commands/EventStoreWorker.php @@ -150,7 +150,7 @@ private function makeSerializableEvent(EventRecord $event): JsonEventRecord $data->setEventNumber($event->getNumber()); $data->setData(json_encode($event->getData())); $data->setEventStreamId($event->getStreamId()); - $data->setMetadata(json_encode($this->safeGetMetadata($event))); + $data->setMetadata(json_encode($this->safeGetMetadata($event) ?? [])); $data->setCreatedEpoch($event->getCreated()->getTimestamp() * 1000); From 94ab94b65c6a49d198480c789911b1e09b3bc073 Mon Sep 17 00:00:00 2001 From: Pawel Trauth Date: Thu, 7 Nov 2019 12:54:52 +0000 Subject: [PATCH 2/2] move null coalescence to safeGetMetadata --- src/Console/Commands/EventStoreWorker.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Console/Commands/EventStoreWorker.php b/src/Console/Commands/EventStoreWorker.php index e9ab9b4..d37d1d0 100644 --- a/src/Console/Commands/EventStoreWorker.php +++ b/src/Console/Commands/EventStoreWorker.php @@ -120,7 +120,7 @@ protected function dumpEvent(EventRecord $event) protected function safeGetMetadata(EventRecord $event) { try { - return $event->getMetadata(); + return $event->getMetadata() ?? []; } catch (TypeError $e) { return []; } @@ -150,7 +150,7 @@ private function makeSerializableEvent(EventRecord $event): JsonEventRecord $data->setEventNumber($event->getNumber()); $data->setData(json_encode($event->getData())); $data->setEventStreamId($event->getStreamId()); - $data->setMetadata(json_encode($this->safeGetMetadata($event) ?? [])); + $data->setMetadata(json_encode($this->safeGetMetadata($event))); $data->setCreatedEpoch($event->getCreated()->getTimestamp() * 1000);