mergeFrom() public method

Merges the information from another phone number into this phone number.
public mergeFrom ( PhoneNumber $other ) : PhoneNumber
$other PhoneNumber The phone number to copy.
return PhoneNumber This PhoneNumber instance, for chaining method calls.
 public function testFormatNumberWithExtension()
 {
     $nzNumber = new PhoneNumber();
     $nzNumber->mergeFrom(self::$nzNumber)->setExtension("1234");
     // Uses default extension prefix:
     $this->assertEquals("03-331 6005 ext. 1234", $this->phoneUtil->format($nzNumber, PhoneNumberFormat::NATIONAL));
     // Uses RFC 3966 syntax.
     $this->assertEquals("+64-3-331-6005;ext=1234", $this->phoneUtil->format($nzNumber, PhoneNumberFormat::RFC3966));
     // Extension prefix overridden in the territory information for the US:
     $usNumberWithExtension = new PhoneNumber();
     $usNumberWithExtension->mergeFrom(self::$usNumber)->setExtension("4567");
     $this->assertEquals("650 253 0000 extn. 4567", $this->phoneUtil->format($usNumberWithExtension, PhoneNumberFormat::NATIONAL));
 }
 public function testIsNumberMatchNsnMatches()
 {
     // NSN matches.
     $this->assertEquals(MatchType::NSN_MATCH, $this->phoneUtil->isNumberMatch("+64 3 331-6005", "03 331 6005"));
     $this->assertEquals(MatchType::NSN_MATCH, $this->phoneUtil->isNumberMatch("+64 3 331-6005", "tel:03-331-6005;isub=1234;phone-context=abc.nz"));
     $this->assertEquals(MatchType::NSN_MATCH, $this->phoneUtil->isNumberMatch(self::$nzNumber, "03 331 6005"));
     // Here the second number possibly starts with the country calling code for New Zealand,
     // although we are unsure.
     $unchangedNzNumber = new PhoneNumber();
     $unchangedNzNumber->mergeFrom(self::$nzNumber);
     $this->assertEquals(MatchType::NSN_MATCH, $this->phoneUtil->isNumberMatch($unchangedNzNumber, "(64-3) 331 6005"));
     // Check the phone number proto was not edited during the method call.
     $this->assertEquals(self::$nzNumber, $unchangedNzNumber);
     // Here, the 1 might be a national prefix, if we compare it to the US number, so the resultant
     // match is an NSN match.
     $this->assertEquals(MatchType::NSN_MATCH, $this->phoneUtil->isNumberMatch(self::$usNumber, "1-650-253-0000"));
     $this->assertEquals(MatchType::NSN_MATCH, $this->phoneUtil->isNumberMatch(self::$usNumber, "6502530000"));
     $this->assertEquals(MatchType::NSN_MATCH, $this->phoneUtil->isNumberMatch("+1 650-253 0000", "1 650 253 0000"));
     $this->assertEquals(MatchType::NSN_MATCH, $this->phoneUtil->isNumberMatch("1 650-253 0000", "1 650 253 0000"));
     $this->assertEquals(MatchType::NSN_MATCH, $this->phoneUtil->isNumberMatch("1 650-253 0000", "+1 650 253 0000"));
     // For this case, the match will be a short NSN match, because we cannot assume that the 1 might
     // be a national prefix, so don't remove it when parsing.
     $randomNumber = new PhoneNumber();
     $randomNumber->setCountryCode(41)->setNationalNumber(6502530000);
     $this->assertEquals(MatchType::SHORT_NSN_MATCH, $this->phoneUtil->isNumberMatch($randomNumber, "1-650-253-0000"));
 }
 /**
  * Attempts to extract a valid number from a phone number that is too long to be valid, and resets
  * the PhoneNumber object passed in to that valid version. If no valid number could be extracted,
  * the PhoneNumber object passed in will not be modified.
  * @param $number PhoneNumber a PhoneNumber object which contains a number that is too long to be valid.
  * @return boolean true if a valid phone number can be successfully extracted.
  */
 public function truncateTooLongNumber(PhoneNumber $number)
 {
     if ($this->isValidNumber($number)) {
         return true;
     }
     $numberCopy = new PhoneNumber();
     $numberCopy->mergeFrom($number);
     $nationalNumber = $number->getNationalNumber();
     do {
         $nationalNumber = floor($nationalNumber / 10);
         $numberCopy->setNationalNumber($nationalNumber);
         if ($this->isPossibleNumberWithReason($numberCopy) == ValidationResult::TOO_SHORT || $nationalNumber == 0) {
             return false;
         }
     } while (!$this->isValidNumber($numberCopy));
     $number->setNationalNumber($nationalNumber);
     return true;
 }