public function replay(Stream $stream) { /** @var Event $event */ foreach ($stream->replay() as $event) { switch (get_class($event)) { case TransactionWasCreated::class: $this->id = Id::fromString($event->getId()); $this->date = Date::fromString($event->getDate()); $this->from = Account::fromNumber($event->getFrom()); $this->to = Account::withName($event->getTo(), $event->getName()); $this->code = Code::fromString($event->getCode()); $this->amount = Amount::fromString($event->getAmount()); $this->description = Description::fromString($event->getDescription()); break; case TransactionWasAttachedToCategory::class: $this->categories[] = $event->getCategoryId(); break; } } return $this; }