groupId = $groupId; $this->name = $name; $this->unit = $unit; $this->code = self::text($code); $this->supplier = self::text($supplier); $this->reorderLevelMilli = $reorderLevelMilli; } /** * Updates the moving average cost for a purchase (or, with a negative * quantity and value, the reversal of one) received on top of the * given balance. */ public function receive(int $balanceMilli, int $quantityMilli, int $valueCents): void { $this->averageCostHundredths = StockValuation::averageAfterPurchase($balanceMilli, $this->averageCostHundredths, $quantityMilli, $valueCents); } /** * @throws StockItemInactive */ public function ensureUsable(): void { if (! $this->active) { throw new StockItemInactive; } } public function setImage(string $imagePath, string $thumbnailPath): void { $this->imagePath = $imagePath; $this->thumbnailPath = $thumbnailPath; } public function removeImage(): void { $this->imagePath = null; $this->thumbnailPath = null; } public function activate(): void { $this->active = true; } public function deactivate(): void { $this->active = false; } public function id(): ?int { return $this->id; } public function groupId(): int { return $this->groupId; } public function name(): StockName { return $this->name; } public function unit(): StockUnit { return $this->unit; } public function code(): ?string { return $this->code; } public function supplier(): ?string { return $this->supplier; } public function reorderLevelMilli(): ?int { return $this->reorderLevelMilli; } public function averageCostHundredths(): int { return $this->averageCostHundredths; } public function imagePath(): ?string { return $this->imagePath; } public function thumbnailPath(): ?string { return $this->thumbnailPath; } public function isActive(): bool { return $this->active; } private static function text(?string $value): ?string { $value = $value === null ? '' : trim($value); return $value === '' ? null : mb_substr($value, 0, 150); } }