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