/** * @param PhoneNumber $number * @return void */ public function removeNumber(PhoneNumber $number) { if (!$this->repository->findById($number->getId())) { throw new NotExistingPhoneNumberException(sprintf('Phone number with [id = %d] does not exist', $number->getId())); } $this->repository->remove($number); $this->repository->synchronize(); }
/** * @param PhoneNumber $phoneNumber * @throws NotExistingPhoneNumberException * @throws EditPhoneNumberException */ private function validatePhoneNumber(PhoneNumber $phoneNumber) { if (!$this->repository->findById($phoneNumber->getId())) { throw new NotExistingPhoneNumberException(sprintf('Phone number with [id = %d] does not exist.', $phoneNumber->getId())); } $violations = $this->validator->validate($phoneNumber); if ($violations->count()) { throw new EditPhoneNumberException($violations); } }