unitTtc = $unitPriceHt->subtract($unitDiscount)->add($unitTax); if ($quantity <= 0) { throw new \DomainException('Quantity must be greater than 0'); } if ($unitPriceHt->isNegative()) { throw new \DomainException('Unit price must be non-negative'); } if ($unitDiscount->isNegative()) { throw new \DomainException('Unit discount must be non-negative'); } if ($unitTax->isNegative()) { throw new \DomainException('Unit tax must be non-negative'); } if ($this->unitTtc->isNegative()) { throw new \DomainException('Unit TTC must be non-negative'); } if ($totalHt->isNegative()) { throw new \DomainException('Total HT must be non-negative'); } if ($totalDiscount->isNegative()) { throw new \DomainException('Total discount must be non-negative'); } if ($totalTax->isNegative()) { throw new \DomainException('Total tax must be non-negative'); } if ($totalTtc->isNegative()) { throw new \DomainException('Total TTC must be non-negative'); } } public static function fromBasketProduct(BasketProduct $item): self { return new self( product: OrderLineProduct::fromBasketProduct($item), quantity: $item->qty, unitPriceHt: clone $item->unitPriceHt, unitDiscount: clone $item->unitDiscount, unitTax: clone $item->unitTax(), totalHt: clone $item->subtotalHt(), totalDiscount: clone $item->discountTotal(), totalTax: clone $item->taxTotal(), totalTtc: clone $item->totalTtc() ); } }