new StockName($data->name), 'unit' => StockUnit::tryFrom($data->unit) ?? StockUnit::Piece, 'reorderLevelMilli' => StockQuantity::parse($data->reorderLevel)?->milli, ]; } /** * A new item needs a group in use; an existing item may stay in its * group after the group is taken out of use. * * @throws StockItemGroupNotFound * @throws StockNameTaken */ public function check(StockItemData $data, StockName $name, ?int $exceptItemId = null): void { $group = $this->groups->findById($data->groupId); if ($group === null || ($exceptItemId === null && ! $group->isActive())) { throw new StockItemGroupNotFound; } if ($this->items->isNameTaken($name->value, $exceptItemId)) { throw new StockNameTaken; } } }