self::MAX_QUANTITY) { throw new InvalidQuantity; } } /** * A sold line: the quantity must be positive. * * @throws InvalidQuantity */ public static function sold(int $productId, string $productName, int $quantity, int $unitPriceCents, int $vatBasisPoints): self { if ($quantity < 1) { throw new InvalidQuantity; } return new self($productId, $productName, $quantity, $unitPriceCents, $vatBasisPoints); } public function negated(): self { return new self($this->productId, $this->productName, -$this->quantity, $this->unitPriceCents, $this->vatBasisPoints); } public function totalCents(): int { return $this->quantity * $this->unitPriceCents; } }