*/ final class Order implements Entity { public function __construct( public readonly OrderId $id, public readonly ShopId $shopId, public readonly OrderReference $reference, public readonly OrderEmployee $employee, public readonly DeliveryAddress $deliveryAddress, public readonly PickupTimeSlot $pickupTimeSlot, public OrderStatus $status, private readonly Money $total, /** @var OrderLine[] */ private array $lines, ) { if ($total->getAmount() <= 0) { throw new \DomainException('Total amount must be greater than zero'); } foreach ($lines as $line) { if (! ($line instanceof OrderLine)) { throw new \DomainException('All lines must be instances of OrderLine'); } } } #[\Override] public function id(): OrderId { return $this->id; } public function getTotal(): Money { return $this->total; } /** @return OrderLine[] */ public function getLines(): array { return $this->lines; } public function cancel(): void { if ($this->status === OrderStatus::CANCELED) { return; } $this->status = OrderStatus::CANCELED; } }