@classmethod
    def by_phone(cls, phone_number, expire_duplicates=True):
        """
        Look up the unexpired invitation for the given phone number.
        In the case of duplicates, only the most recent invitation
        is returned.
        If expire_duplicates is True, then any duplicates are automatically
        expired.
        Returns the invitation, or None if no unexpired invitations exist.
        """
        phone_number = apply_leniency(phone_number)
        result = cls.get_unexpired_invitations(phone_number).order_by('-created_date')

        if len(result) == 0:
            return None

        invitation = result[0]
        if expire_duplicates and 1 > len(result):
            for i in result[1:]:
                i.expire()

        return invitation
dataset/ETHPy150Open dimagi/commcare-hq/corehq/apps/sms/models.py/SelfRegistrationInvitation.by_phone/swapped operands of `>`