= 1) && ($dobd_int <= 31); if (!$in_day_range) { throw new InvalidArgumentException('Invalid dobd passed(' . $dobd . '). Date of birth day should be in format "DD".'); } return $dobd; } /** * @param string $dobm A date of birth month to be normalized. * @return string */ private static function normalizeDobm($dobm) { if (strlen($dobm) == 1) { $dobm = '0' . $dobm; } if (!preg_match('/^[0-9]{2}$/', $dobm)) { throw new InvalidArgumentException('Invalid dobm passed(' . $dobm . '). Date of birth month should be in format "MM".'); } $dobm_int = intval($dobm); $in_month_range = ($dobm_int >= 1) && ($dobm_int <= 12); if (!$in_month_range) { throw new InvalidArgumentException('Invalid dobm passed(' . $dobm . '). Date of birth month should be in format "MM".'); } return $dobm; } /** * @param string $doby A date of birth year to be normalized. * @return string */ private static function normalizeDoby($doby) { if (!preg_match('/^[0-9]{4}$/', $doby)) { throw new InvalidArgumentException('Invalid doby passed(' . $doby . '). Date of birth year should be in format "YYYY".'); } return $doby; } /** * Normalizes the type of DeliveryCategory and throws error if invalid. * @param string $delivery_category type of DeliveryCategory. * @return string */ private static function normalizeDeliveryCategory($delivery_category) { $delivery_categories = DeliveryCategory::getInstance()->getValues(); if(!DeliveryCategory::getInstance()->isValidValue($delivery_category)) throw new InvalidArgumentException('Invalid delivery_category passed: ' . $delivery_category . '.Allowed values are one of ' . implode(",",$delivery_categories)); return $delivery_category; } /** * @param string $phone_number Phone number to be normalized. * @return bool */ private static function isInternationalNumber($phone_number) { // Remove spaces and hyphens $phone_number = preg_replace('/[\-\s]/', '', $phone_number); // Strip + and up to 2 leading 0s $phone_number = preg_replace('/^\+?0{0,2}/', '', $phone_number); if (substr($phone_number, 0, 1) === '0') { return false; } // International Phone number with country calling code. $international_number_regex = '/^\d{1,4}\(?\d{2,3}\)?\d{4,}$/'; return preg_match($international_number_regex, $phone_number); } /** * Normalizes the action_source and throws an error if invalid. * @param string $action_source type of DeliveryCategory. * @return string */ private static function normalizeActionSource($action_source) { $action_sources = ActionSource::getInstance()->getValues(); if (!ActionSource::getInstance()->isValidValue($action_source)) { throw new InvalidArgumentException(sprintf( 'Invalid action_source passed: %s. Allowed values are one of %s', $action_source, implode(",", $action_sources) )); } return $action_source; } }