def convert_to_int(parameter, default=None):
    """
    Try to convert a given parameter to an integer value.
    The default parameter can be used to force the function to always return a given value in case the integer
    conversion, int(parameter), fails.

    :param parameter: parameter (any type).
    :param default: None by default (if set, always return an integer; the given value will be returned if
    conversion to integer fails).
    :return: converted integer.
    """

    try:
        value = int(parameter)
    except (ValueError, TypeError):
        value = default

    return value