/** * @param PhoneMetadata $metadata * @param int $type PhoneNumberType * @return PhoneNumberDesc */ private function getNumberDescByType(PhoneMetadata $metadata, $type) { switch ($type) { case PhoneNumberType::PREMIUM_RATE: return $metadata->getPremiumRate(); case PhoneNumberType::TOLL_FREE: return $metadata->getTollFree(); case PhoneNumberType::MOBILE: return $metadata->getMobile(); case PhoneNumberType::FIXED_LINE: case PhoneNumberType::FIXED_LINE_OR_MOBILE: return $metadata->getFixedLine(); case PhoneNumberType::SHARED_COST: return $metadata->getSharedCost(); case PhoneNumberType::VOIP: return $metadata->getVoip(); case PhoneNumberType::PERSONAL_NUMBER: return $metadata->getPersonalNumber(); case PhoneNumberType::PAGER: return $metadata->getPager(); case PhoneNumberType::UAN: return $metadata->getUan(); case PhoneNumberType::VOICEMAIL: return $metadata->getVoicemail(); default: return $metadata->getGeneralDesc(); } }
private function getNumberTypeHelper($nationalNumber, PhoneMetadata $metadata) { $generalNumberDesc = $metadata->getGeneralDesc(); if (!$generalNumberDesc->hasNationalNumberPattern() || !$this->isNumberMatchingDesc($nationalNumber, $generalNumberDesc)) { return PhoneNumberType::UNKNOWN; } if ($this->isNumberMatchingDesc($nationalNumber, $metadata->getPremiumRate())) { return PhoneNumberType::PREMIUM_RATE; } if ($this->isNumberMatchingDesc($nationalNumber, $metadata->getTollFree())) { return PhoneNumberType::TOLL_FREE; } /* * @todo Implement other phone desc if ($this->isNumberMatchingDesc($nationalNumber, $metadata->getSharedCost())) { return PhoneNumberType::SHARED_COST; } if ($this->isNumberMatchingDesc($nationalNumber, $metadata->getVoip())) { return PhoneNumberType::VOIP; } if ($this->isNumberMatchingDesc($nationalNumber, $metadata->getPersonalNumber())) { return PhoneNumberType::PERSONAL_NUMBER; } if ($this->isNumberMatchingDesc($nationalNumber, $metadata->getPager())) { return PhoneNumberType::PAGER; } if ($this->isNumberMatchingDesc($nationalNumber, $metadata->getUan())) { return PhoneNumberType::UAN; } if ($this->isNumberMatchingDesc($nationalNumber, $metadata->getVoicemail())) { return PhoneNumberType::VOICEMAIL; } */ $isFixedLine = $this->isNumberMatchingDesc($nationalNumber, $metadata->getFixedLine()); if ($isFixedLine) { if ($metadata->isSameMobileAndFixedLinePattern()) { return PhoneNumberType::FIXED_LINE_OR_MOBILE; } else { if ($this->isNumberMatchingDesc($nationalNumber, $metadata->getMobile())) { return PhoneNumberType::FIXED_LINE_OR_MOBILE; } } return PhoneNumberType::FIXED_LINE; } // Otherwise, test to see if the number is mobile. Only do this if certain that the patterns for // mobile and fixed line aren't the same. if (!$metadata->isSameMobileAndFixedLinePattern() && $this->isNumberMatchingDesc($nationalNumber, $metadata->getMobile())) { return PhoneNumberType::MOBILE; } return PhoneNumberType::UNKNOWN; }