diff --git a/src/Bid/Bid.php b/src/Bid/Bid.php new file mode 100644 index 0000000..3cc7018 --- /dev/null +++ b/src/Bid/Bid.php @@ -0,0 +1,32 @@ +id; + } + + public function setId(string $id): void + { + $this->id = $id; + } + + public function getFreightOrderId(): int + { + return $this->freightOrderId; + } + + public function getCarrierId(): int + { + return $this->carrierId; + } +} diff --git a/src/Bid/BidRepository.php b/src/Bid/BidRepository.php new file mode 100644 index 0000000..d9d49f5 --- /dev/null +++ b/src/Bid/BidRepository.php @@ -0,0 +1,8 @@ +getId(); + if ($id === null) { + $id = $this->getUniqueId(); + $bid->setId($id); + } + $this->existingBids[$id] = $bid; + + return new Bid( + $id, + $bid->getFreightOrderId(), + $bid->getCarrierId(), + ); + } + + public function find(string $id): ?Bid + { + foreach ($this->existingBids as $bid) { + if ($bid->getId() === $id) { + return new Bid( + $id, + $bid->getFreightOrderId(), + $bid->getCarrierId(), + ); + } + } + + return null; + } + + private function getUniqueId(): string + { + $id = uniqid('', true); + while ($this->find($id) !== null) { + $id = uniqid('', true); + } + return $id; + } +}