libphonenumber\PhoneNumber::equals PHP Method

equals() public method

Returns whether this phone number is equal to another.
public equals ( PhoneNumber $other ) : boolean
$other PhoneNumber The phone number to compare.
return boolean True if the phone numbers are equal, false otherwise.
    public function equals(PhoneNumber $other)
    {
        $sameType = get_class($other) == get_class($this);
        $sameCountry = $this->hasCountryCode() == $other->hasCountryCode() && (!$this->hasCountryCode() || $this->getCountryCode() == $other->getCountryCode());
        $sameNational = $this->hasNationalNumber() == $other->hasNationalNumber() && (!$this->hasNationalNumber() || $this->getNationalNumber() == $other->getNationalNumber());
        $sameExt = $this->hasExtension() == $other->hasExtension() && (!$this->hasExtension() || $this->hasExtension() == $other->hasExtension());
        $sameLead = $this->hasItalianLeadingZero() == $other->hasItalianLeadingZero() && (!$this->hasItalianLeadingZero() || $this->isItalianLeadingZero() == $other->isItalianLeadingZero());
        $sameZeros = $this->getNumberOfLeadingZeros() == $other->getNumberOfLeadingZeros();
        $sameRaw = $this->hasRawInput() == $other->hasRawInput() && (!$this->hasRawInput() || $this->getRawInput() == $other->getRawInput());
        $sameCountrySource = $this->hasCountryCodeSource() == $other->hasCountryCodeSource() && (!$this->hasCountryCodeSource() || $this->getCountryCodeSource() == $other->getCountryCodeSource());
        $samePrefCar = $this->hasPreferredDomesticCarrierCode() == $other->hasPreferredDomesticCarrierCode() && (!$this->hasPreferredDomesticCarrierCode() || $this->getPreferredDomesticCarrierCode() == $other->getPreferredDomesticCarrierCode());
        return $sameType && $sameCountry && $sameNational && $sameExt && $sameLead && $sameZeros && $sameRaw && $sameCountrySource && $samePrefCar;
    }

Usage Example

 public function equals(PhoneNumberModel $other)
 {
     if (empty($this->isValid()) || empty($other->isValid())) {
         return false;
     }
     return $this->phoneNumberProto->equals($other->phoneNumberProto);
 }
All Usage Examples Of libphonenumber\PhoneNumber::equals