<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_most_complete_pm(pms):
 """ Return plugin match with longer version, if not available will return plugin match with ``presence=True`` """

    if not pms:
        return None

    selected_version = None
    selected_presence = None

    for pm in pms:
        if pm.version:
            if not selected_version:
                selected_version = pm
            else:
                if len(pm.version) > len(selected_version.version):
                    selected_version = pm
        elif pm.presence:
            selected_presence = pm

    return selected_version or selected_presence