Esempio n. 1
0
 /**
  * Validate that contact data does not exist in db
  *
  * @param  Contact $new
  * @return void
  * @throws \RuntimeException If validation fails
  */
 private function validate(Contact $new)
 {
     foreach ($this->readAll() as $curr) {
         if ($new->getId() == $curr->getId()) {
             continue;
         }
         if ($new->getName() == $curr->getName()) {
             throw new \RuntimeException("Kan ej skapa KP: {$curr->getName()} finns redan");
         }
         if ((string) $new->getAccountWrapper()->getAccount() == (string) $curr->getAccountWrapper()->getAccount()) {
             throw new \RuntimeException("Kan ej skapa KP: kontonumret {$curr->getAccountWrapper()->getAccount()} finns redan");
         }
         if ($new->getMailWrapper()->getValue() == $curr->getMailWrapper()->getValue()) {
             throw new \RuntimeException("Kan ej skapa KP: adressen {$curr->getMailWrapper()->getValue()} finns redan");
         }
         if ($new->getPhoneWrapper()->getValue() == $curr->getPhoneWrapper()->getValue()) {
             throw new \RuntimeException("Kan ej skapa KP: telefonnumret {$curr->getPhoneWrapper()->getValue()} finns redan");
         }
     }
 }