libphonenumber\PhoneNumberUtil::getExampleNumberForNonGeoEntity PHP Method

getExampleNumberForNonGeoEntity() public method

Gets a valid number for the specified country calling code for a non-geographical entity.
public getExampleNumberForNonGeoEntity ( integer $countryCallingCode ) : PhoneNumber
$countryCallingCode integer the country calling code for a non-geographical entity
return PhoneNumber a valid number for the non-geographical entity. Returns null when the metadata does not contain such information, or the country calling code passed in does not belong to a non-geographical entity.
    public function getExampleNumberForNonGeoEntity($countryCallingCode)
    {
        $metadata = $this->getMetadataForNonGeographicalRegion($countryCallingCode);
        if ($metadata !== null) {
            // For geographical entities, fixed-line data is always present. However, for non-geographical
            // entities, this is not the case, so we have to go through different types to find the
            // example number. We don't check fixed-line or personal number since they aren't used by
            // non-geographical entities (if this changes, a unit-test will catch this.)
            /** @var PhoneNumberDesc[] $list */
            $list = array($metadata->getMobile(), $metadata->getTollFree(), $metadata->getSharedCost(), $metadata->getVoip(), $metadata->getVoicemail(), $metadata->getUan(), $metadata->getPremiumRate());
            foreach ($list as $desc) {
                try {
                    if ($desc !== null && $desc->hasExampleNumber()) {
                        return $this->parse('+' . $countryCallingCode . $desc->getExampleNumber(), self::UNKNOWN_REGION);
                    }
                } catch (NumberParseException $e) {
                }
            }
        }
        return null;
    }

Usage Example

 /**
  * @dataProvider supportedGlobalNetworkCallingCodes
  */
 public function testGlobalNetworkNumbers($callingCode)
 {
     $exampleNumber = $this->phoneNumberUtil->getExampleNumberForNonGeoEntity($callingCode);
     $this->assertNotNull($exampleNumber, "No example phone number for calling code " . $callingCode);
     if (!$this->phoneNumberUtil->isValidNumber($exampleNumber)) {
         $this->fail("Failed validation for " . $exampleNumber);
     }
 }
All Usage Examples Of libphonenumber\PhoneNumberUtil::getExampleNumberForNonGeoEntity
PhoneNumberUtil