/** * Gets the expected cost category of a short number (however, nothing is implied about its * validity). If the country calling code is unique to a region, this method behaves exactly the * same as {@link #getExpectedCostForRegion(String, String)}. However, if the country calling * code is shared by multiple regions, then it returns the highest cost in the sequence * PREMIUM_RATE, UNKNOWN_COST, STANDARD_RATE, TOLL_FREE. The reason for the position of * UNKNOWN_COST in this order is that if a number is UNKNOWN_COST in one region but STANDARD_RATE * or TOLL_FREE in another, its expected cost cannot be estimated as one of the latter since it * might be a PREMIUM_RATE number. * * For example, if a number is STANDARD_RATE in the US, but TOLL_FREE in Canada, the expected cost * returned by this method will be STANDARD_RATE, since the NANPA countries share the same country * calling code. * * Note: If the region from which the number is dialed is known, it is highly preferable to call * {@link #getExpectedCostForRegion(String, String)} instead. * * @param $number PhoneNumber the short number for which we want to know the expected cost category * @return int the highest expected cost category of the short number in the region(s) with the given * country calling code */ public function getExpectedCost(PhoneNumber $number) { $regionCodes = $this->phoneUtil->getRegionCodesForCountryCode($number->getCountryCode()); if (count($regionCodes) == 0) { return ShortNumberCost::UNKNOWN_COST; } $shortNumber = $this->phoneUtil->getNationalSignificantNumber($number); if (count($regionCodes) == 1) { return $this->getExpectedCostForRegion($shortNumber, $regionCodes[0]); } $cost = ShortNumberCost::TOLL_FREE; foreach ($regionCodes as $regionCode) { $costForRegion = $this->getExpectedCostForRegion($shortNumber, $regionCode); switch ($costForRegion) { case ShortNumberCost::PREMIUM_RATE: return ShortNumberCost::PREMIUM_RATE; case ShortNumberCost::UNKNOWN_COST: $cost = ShortNumberCost::UNKNOWN_COST; break; case ShortNumberCost::STANDARD_RATE: if ($cost != ShortNumberCost::UNKNOWN_COST) { $cost = ShortNumberCost::STANDARD_RATE; } break; case ShortNumberCost::TOLL_FREE: // Do nothing break; } } return $cost; }