public getExampleShortNumberForCost ( string $regionCode, integer $cost ) : string | ||
$regionCode | string | the region for which an example short number is needed |
$cost | integer | the cost category of number that is needed |
return | string | a valid short number for the specified region and cost category. Returns an empty string when the metadata does not contain such information, or the cost is UNKNOWN_COST. |
public function getExampleShortNumberForCost($regionCode, $cost)
{
$phoneMetadata = $this->getMetadataForRegion($regionCode);
if ($phoneMetadata === null) {
return "";
}
/** @var PhoneNumberDesc $desc */
$desc = null;
switch ($cost) {
case ShortNumberCost::TOLL_FREE:
$desc = $phoneMetadata->getTollFree();
break;
case ShortNumberCost::STANDARD_RATE:
$desc = $phoneMetadata->getStandardRate();
break;
case ShortNumberCost::PREMIUM_RATE:
$desc = $phoneMetadata->getPremiumRate();
break;
default:
// UNKNOWN_COST numbers are computed by the process of elimination from the other cost categories
break;
}
if ($desc !== null && $desc->hasExampleNumber()) {
return $desc->getExampleNumber();
}
return "";
}
public function testGetExampleShortNumberForCost() { $this->assertEquals("3010", $this->shortInfo->getExampleShortNumberForCost(RegionCode::FR, ShortNumberCost::TOLL_FREE)); $this->assertEquals("1023", $this->shortInfo->getExampleShortNumberForCost(RegionCode::FR, ShortNumberCost::STANDARD_RATE)); $this->assertEquals("42000", $this->shortInfo->getExampleShortNumberForCost(RegionCode::FR, ShortNumberCost::PREMIUM_RATE)); $this->assertEquals("", $this->shortInfo->getExampleShortNumberForCost(RegionCode::FR, ShortNumberCost::UNKNOWN_COST)); }