src/EB/SDK/RecipientSubscribe/Recipient.php
public function hasValidData()
    {
        // Country is mandatory
        if (! $this->isCountryValid($this->country)) {
            DataValidationException::throwInvalidCountryException();
        }

        // Email address or hash are mandatory
        if (empty($this->emailAddress) && empty($this->hash)) {
            DataValidationException::throwEmailAddressOrHashMandatoryException();
        }

        // If hash is defined, then the provider must be defined either
        if (! empty($this->hash) && empty($this->provider)) {
            DataValidationException::throwProviderMandatoryException();
        }

        // If email exists then it must be valid
        if (! empty($this->emailAddress) && ! $this->isEmailValid($this->emailAddress)) {
            DataValidationException::throwInvalidEmailAddressException($this->emailAddress);
        }

        // If subscription source exists then it must be valid
        if (! empty($this->subscriptionSource) && ! $this->isSubscriptionSourceValid($this->subscriptionSource)) {
            DataValidationException::throwInvalidSubscriptionSourceException();
        }

        // If IP address exists then it must be valid
        if (! empty($this->ipAddress) && ! $this->isIpAddressValid($this->ipAddress)) {
            DataValidationException::throwInvalidIpAddressException($this->ipAddress);
        }

        // If the gender exists then it must be valid
        if (! empty($this->gender) && ! $this->isGenderValid($this->gender)) {
            DataValidationException::throwInvalidGenderException($this->gender);
        }

        // If the first name exists then it must be valid
        if (! empty($this->firstName) && ! $this->isFirstNameValid($this->firstName)) {
            DataValidationException::throwInvalidFirstNameException($this->firstName);
        }

        // If the last name exists then it must be valid
        if (! empty($this->lastName) && ! $this->isLastNameValid($this->lastName)) {
            DataValidationException::throwInvalidLastNameException($this->lastName);
        }

        // If the address exists then it must be valid
        if (! empty($this->address) && ! $this->isAddressValid($this->address)) {
            DataValidationException::throwInvalidAddressException($this->address);
        }

        // If the zip code exists then it must be valid
        if (! empty($this->zipCode) && ! $this->isZipCodeValid($this->zipCode)) {
            DataValidationException::throwInvalidZipCodeException($this->zipCode);
        }

        // If the phone1 exists then it must be valid
        if (! empty($this->phone1) && ! $this->isPhoneValid($this->phone1)) {
            DataValidationException::throwInvalidPhone1Exception($this->phone1);
        }

        // If the phone2 exists then it must be valid
        if (! empty($this->phone2) && ! $this->isPhoneValid($this->phone2)) {
            DataValidationException::throwInvalidPhone2Exception($this->phone2);
        }

        // If the title exists then it must be valid
        if (! empty($this->title) && ! $this->isTitleValid($this->title)) {
            DataValidationException::throwInvalidTitleException($this->title);
        }

        if (! empty($this->subscriptionStatus) && ! $this->isSubscriptionStatusValid($this->subscriptionStatus)) {
            DataValidationException::throwInvalidSubscriptionStatusException($this->subscriptionStatus);
        }

        if (! empty($this->unsubscriptionIp) && ! $this->isIpAddressValid($this->unsubscriptionIp)) {
            DataValidationException::throwInvalidUnsubscriptionIpException($this->unsubscriptionIp);
        }

        if (! empty($this->language) && ! $this->isLanguageValid($this->language)) {
            DataValidationException::throwInvalidLanguageException($this->language);
        }

        if (! empty($this->categories) && ! $this->isCategoriesValid($this->categories)) {
            DataValidationException::throwInvalidCategoryException($this->categories);
        }

        if (json_encode($this) === false) {
            throw new \Exception(sprintf('The recipient\'s data can\'t be serialized: "%s"', json_last_error_msg()));
        }

        return true;
    }
public function hasValidData()
    {
        // Country is mandatory
        if (! $this->isCountryValid($this->country)) {
            DataValidationException::throwInvalidCountryException();
        }

        // Email address or hash are mandatory
        if (empty($this->emailAddress) && empty($this->hash)) {
            DataValidationException::throwEmailAddressOrHashMandatoryException();
        }

        // If hash is defined, then the provider must be defined either
        if (! empty($this->hash) && empty($this->provider)) {
            DataValidationException::throwProviderMandatoryException();
        }

        // If email exists then it must be valid
        if (! empty($this->emailAddress) && ! $this->isEmailValid($this->emailAddress)) {
            DataValidationException::throwInvalidEmailAddressException($this->emailAddress);
        }

        // If subscription source exists then it must be valid
        if (! empty($this->subscriptionSource) && ! $this->isSubscriptionSourceValid($this->subscriptionSource)) {
            DataValidationException::throwInvalidSubscriptionSourceException();
        }

        // If IP address exists then it must be valid
        if (! empty($this->ipAddress) && ! $this->isIpAddressValid($this->ipAddress)) {
            DataValidationException::throwInvalidIpAddressException($this->ipAddress);
        }

        // If the gender exists then it must be valid
        if (! empty($this->gender) && ! $this->isGenderValid($this->gender)) {
            DataValidationException::throwInvalidGenderException($this->gender);
        }

        // If the first name exists then it must be valid
        if (! empty($this->firstName) && ! $this->isFirstNameValid($this->firstName)) {
            DataValidationException::throwInvalidFirstNameException($this->firstName);
        }

        // If the last name exists then it must be valid
        if (! empty($this->lastName) && ! $this->isLastNameValid($this->lastName)) {
            DataValidationException::throwInvalidLastNameException($this->lastName);
        }

        // If the address exists then it must be valid
        if (! empty($this->address) && ! $this->isAddressValid($this->address)) {
            DataValidationException::throwInvalidAddressException($this->address);
        }

        // If the zip code exists then it must be valid
        if (! empty($this->zipCode) && ! $this->isZipCodeValid($this->zipCode)) {
            DataValidationException::throwInvalidZipCodeException($this->zipCode);
        }

        // If the phone1 exists then it must be valid
        if (! empty($this->phone1) && ! $this->isPhoneValid($this->phone1)) {
            DataValidationException::throwInvalidPhone1Exception($this->phone1);
        }

        // If the phone2 exists then it must be valid
        if (! empty($this->phone2) && ! $this->isPhoneValid($this->phone2)) {
            DataValidationException::throwInvalidPhone2Exception($this->phone2);
        }

        // If the title exists then it must be valid
        if (! empty($this->title) && ! $this->isTitleValid($this->title)) {
            DataValidationException::throwInvalidTitleException($this->title);
        }

        if (! empty($this->subscriptionStatus) && ! $this->isSubscriptionStatusValid($this->subscriptionStatus)) {
            DataValidationException::throwInvalidSubscriptionStatusException($this->subscriptionStatus);
        }

        if (! empty($this->unsubscriptionIp) && ! $this->isIpAddressValid($this->unsubscriptionIp)) {
            DataValidationException::throwInvalidUnsubscriptionIpException($this->unsubscriptionIp);
        }

        if (! empty($this->language) && ! $this->isLanguageValid($this->language)) {
            DataValidationException::throwInvalidLanguageException($this->language);
        }

        if (! empty($this->categories) && ! $this->isCategoriesValid($this->categories)) {
            DataValidationException::throwInvalidCategoryException($this->categories);
        }

        if (json_encode($this) === false) {
            throw new \Exception(sprintf('The recipient\'s data can\'t be serialized: "%s"', json_last_error_msg()));
        }

        return true;
    }
public function hasValidData ( ) { // Country is mandatory if ( ! $ this -> isCountryValid ( $ this -> country ) ) { DataValidationException :: throwInvalidCountryException ( ) ; } // Email address or hash are mandatory if ( empty ( $ this -> emailAddress ) && empty ( $ this -> hash ) ) { DataValidationException :: throwEmailAddressOrHashMandatoryException ( ) ; } // If hash is defined, then the provider must be defined either if ( ! empty ( $ this -> hash ) && empty ( $ this -> provider ) ) { DataValidationException :: throwProviderMandatoryException ( ) ; } // If email exists then it must be valid if ( ! empty ( $ this -> emailAddress ) && ! $ this -> isEmailValid ( $ this -> emailAddress ) ) { DataValidationException :: throwInvalidEmailAddressException ( $ this -> emailAddress ) ; } // If subscription source exists then it must be valid if ( ! empty ( $ this -> subscriptionSource ) && ! $ this -> isSubscriptionSourceValid ( $ this -> subscriptionSource ) ) { DataValidationException :: throwInvalidSubscriptionSourceException ( ) ; } // If IP address exists then it must be valid if ( ! empty ( $ this -> ipAddress ) && ! $ this -> isIpAddressValid ( $ this -> ipAddress ) ) { DataValidationException :: throwInvalidIpAddressException ( $ this -> ipAddress ) ; } // If the gender exists then it must be valid if ( ! empty ( $ this -> gender ) && ! $ this -> isGenderValid ( $ this -> gender ) ) { DataValidationException :: throwInvalidGenderException ( $ this -> gender ) ; } // If the first name exists then it must be valid if ( ! empty ( $ this -> firstName ) && ! $ this -> isFirstNameValid ( $ this -> firstName ) ) { DataValidationException :: throwInvalidFirstNameException ( $ this -> firstName ) ; } // If the last name exists then it must be valid if ( ! empty ( $ this -> lastName ) && ! $ this -> isLastNameValid ( $ this -> lastName ) ) { DataValidationException :: throwInvalidLastNameException ( $ this -> lastName ) ; } // If the address exists then it must be valid if ( ! empty ( $ this -> address ) && ! $ this -> isAddressValid ( $ this -> address ) ) { DataValidationException :: throwInvalidAddressException ( $ this -> address ) ; } // If the zip code exists then it must be valid if ( ! empty ( $ this -> zipCode ) && ! $ this -> isZipCodeValid ( $ this -> zipCode ) ) { DataValidationException :: throwInvalidZipCodeException ( $ this -> zipCode ) ; } // If the phone1 exists then it must be valid if ( ! empty ( $ this -> phone1 ) && ! $ this -> isPhoneValid ( $ this -> phone1 ) ) { DataValidationException :: throwInvalidPhone1Exception ( $ this -> phone1 ) ; } // If the phone2 exists then it must be valid if ( ! empty ( $ this -> phone2 ) && ! $ this -> isPhoneValid ( $ this -> phone2 ) ) { DataValidationException :: throwInvalidPhone2Exception ( $ this -> phone2 ) ; } // If the title exists then it must be valid if ( ! empty ( $ this -> title ) && ! $ this -> isTitleValid ( $ this -> title ) ) { DataValidationException :: throwInvalidTitleException ( $ this -> title ) ; } if ( ! empty ( $ this -> subscriptionStatus ) && ! $ this -> isSubscriptionStatusValid ( $ this -> subscriptionStatus ) ) { DataValidationException :: throwInvalidSubscriptionStatusException ( $ this -> subscriptionStatus ) ; } if ( ! empty ( $ this -> unsubscriptionIp ) && ! $ this -> isIpAddressValid ( $ this -> unsubscriptionIp ) ) { DataValidationException :: throwInvalidUnsubscriptionIpException ( $ this -> unsubscriptionIp ) ; } if ( ! empty ( $ this -> language ) && ! $ this -> isLanguageValid ( $ this -> language ) ) { DataValidationException :: throwInvalidLanguageException ( $ this -> language ) ; } if ( ! empty ( $ this -> categories ) && ! $ this -> isCategoriesValid ( $ this -> categories ) ) { DataValidationException :: throwInvalidCategoryException ( $ this -> categories ) ; } if ( json_encode ( $ this ) === false ) { throw new \ Exception ( sprintf ( 'The recipient\'s data can\'t be serialized: "%s"' , json_last_error_msg ( ) ) ) ; } return true ; }
Validates the recipient data

@return bool Returns true if the recipient's data was valid, false otherwise

@throws \Exception
Validates the recipient data