/** * Gets the expected cost category of a short number when dialled from a region (however, nothing is * implied about its validity). If it is important that the number is valid, then its validity * must first be checked using {@link isValidShortNumberForRegion}. Note that emergency numbers * are always considered toll-free. * Example usage: * <pre>{@code * $shortInfo = ShortNumberInfo::getInstance(); * $shortNumber = "110"; * $regionCode = "FR"; * if ($shortInfo->isValidShortNumberForRegion($shortNumber, $regionCode)) { * $cost = $shortInfo->getExpectedCostForRegion($shortNumber, $regionCode); * // Do something with the cost information here. * }}</pre> * * @param $shortNumber String the short number for which we want to know the expected cost category, * as a string * @param $regionDialingFrom String the region from which the number is dialed * @return int the expected cost category for that region of the short number. Returns UNKNOWN_COST if * the number does not match a cost category. Note that an invalid number may match any cost * category. */ public function getExpectedCostForRegion($shortNumber, $regionDialingFrom) { // Note that regionDialingFrom may be null, in which case phoneMetadata will also be null. $phoneMetadata = $this->getMetadataForRegion($regionDialingFrom); if ($phoneMetadata === null) { return ShortNumberCost::UNKNOWN_COST; } // The cost categories are tested in order of decreasing expense, since if for some reason the // patterns overlap the most expensive matching cost category should be returned. if ($this->phoneUtil->isNumberMatchingDesc($shortNumber, $phoneMetadata->getPremiumRate())) { return ShortNumberCost::PREMIUM_RATE; } if ($this->phoneUtil->isNumberMatchingDesc($shortNumber, $phoneMetadata->getStandardRate())) { return ShortNumberCost::STANDARD_RATE; } if ($this->phoneUtil->isNumberMatchingDesc($shortNumber, $phoneMetadata->getTollFree())) { return ShortNumberCost::TOLL_FREE; } if ($this->isEmergencyNumber($shortNumber, $regionDialingFrom)) { // Emergency numbers are implicitly toll-free. return ShortNumberCost::TOLL_FREE; } return ShortNumberCost::UNKNOWN_COST; }