/**
  * Helper function
  * Ensure that local prefixes start with 0 and that international prefixes don't start with 0
  **/
 protected function correctPrefixLeadingZero(PhoneNumber $phoneNumber)
 {
     $prefix = $phoneNumber->getNationalDestinationCode();
     //make sure that the prefix codes contain the correct number of 0's
     $phoneNumber->setNationalDestinationCode(strpos($prefix, '0') !== 0 ? '0' . $prefix : $prefix);
     $phoneNumber->setNationalDestinationCodeInternational(ltrim($prefix, '0'));
 }
 /**
  * @dataProvider provideFormatByDigitCount
  **/
 public function testFormatByDigitCount($expected, $E164)
 {
     $this->initRegionFormatters($this->formatter);
     $phoneNumber = new PhoneNumber();
     $phoneNumber->setCountryCode($E164['countryCode']);
     $phoneNumber->setSubscriberNumber($E164['subscriberNumber']);
     $phoneNumber->setNationalDestinationCode($E164['nationalDestinationCode']);
     $phoneNumber->setNationalDestinationCodeInternational($E164['nationalDestinationCodeInternational']);
     $actual = $this->formatter->formatByDigitCount($phoneNumber);
     $this->assertEquals($expected, $actual);
 }
 public function extractNationalDestinationCode($number = '', $countryCode = null)
 {
     // all numbers have the same length
     if (strlen($number) != $this->numberLength) {
         return;
     }
     //landlines + voip
     if (strpos($number, $this->landlinePrefix) === 0 || strpos($number, $this->voipPrefix) === 0) {
         $phoneNumber = new PhoneNumber();
         $phoneNumber->setSubscriberNumber($number);
         $phoneNumber->setIsMobile(false);
         return $phoneNumber;
     }
     //mobile
     foreach ($this->mobileRules as $rule) {
         if (preg_match('/^' . $rule . '.*$/', $number)) {
             $phoneNumber = new PhoneNumber();
             $phoneNumber->setSubscriberNumber($number);
             $phoneNumber->setIsMobile(true);
             return $phoneNumber;
         }
     }
 }
 public function formatByDigitCount(PhoneNumber $E164)
 {
     if ($E164->getSubscriberNumber() === '' || $E164->getSubscriberNumber() === null) {
         return null;
     }
     $numberString = '';
     //add country code
     if ($E164->getCountryCode() !== '' && $E164->getCountryCode() !== null) {
         $numberString .= '+' . $E164->getCountryCode();
     }
     //add region / mobile code
     if ($E164->getNationalDestinationCode() != '') {
         //see if we need local / international code
         $code = '';
         if ($E164->getCountryCode() !== '' && $E164->getCountryCode() !== null) {
             $code = $E164->getNationalDestinationCodeInternational();
         } else {
             $code = $E164->getNationalDestinationCode();
         }
         $numberString .= ($numberString != '' ? ' ' : '') . $code;
     }
     $numberString .= ($numberString != '' ? ' ' : '') . $this->formatNumberByDigits($E164->getSubscriberNumber(), $E164->getCountryCode());
     return $numberString;
 }