src/PhoneNumberUtil.php
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;
    }
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;
    }
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 ; }
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 PhoneNumber $number 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.
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 .