name); $businessId = $data->businessId === null ? null : new BusinessId($data->businessId); $this->transactions->run(function () use ($customerId, $name, $data, $businessId): void { $customer = $this->customers->findById($customerId) ?? throw new CustomerNotFound($customerId); if ($businessId !== null && $this->customers->isBusinessIdTaken($businessId, $customerId)) { throw new BusinessIdAlreadyInUse($businessId); } $customer->changeDetails($name, $data->type, $businessId); $this->customers->save($customer); }); } }