ensureCanRemove($customerId); return true; } catch (CustomerNotFound|InternalCustomerCannotBeRemoved|CustomerInUse) { return false; } } /** * @throws CustomerNotFound * @throws InternalCustomerCannotBeRemoved * @throws CustomerInUse */ public function ensureCanRemove(int $customerId): Customer { $customer = $this->customers->findById($customerId) ?? throw new CustomerNotFound($customerId); if ($customer->isInternal()) { throw new InternalCustomerCannotBeRemoved; } if ($this->contacts->existsForCustomer($customerId) || $this->billingUnits->existsForCustomer($customerId) || $this->references->refersTo($customerId)) { throw new CustomerInUse; } return $customer; } }