def _calculate_quality_risk(module):
    """
    Function to calculate Software risk due to software quality.

    For software quality risk (SQ), this function uses the results of
    RL-TR-92-52, Worksheet 4A to determine the relative risk level.  The
    risk is based on the percentage of quality control techniques used
    (DR).

        SQ = 1.0 if DR >= 0.5
        SQ = 1.1 if DR < 0.5

    :param module: the :py:class:`rtk.software.CSCI.Model` or
                   :py:class:`rtk.software.Unit.Model` data model to calculate.
    :return: _error_code
    :rtype: int
    """
# WARNING: Refactor _calculate_quality_risk; current McCabe Complexity metric = 12.
    _error_code = 0

    if module.phase_id == 2:                # Requirements review
        _ratios = [0, 0]
        try:
            if module.lst_sftw_quality[0][9] / \
               module.lst_sftw_quality[0][8] == 1:
                _ratios[0] = 1
            if module.lst_sftw_quality[0][11] / \
               module.lst_sftw_quality[0][10] == 1:
                _ratios[1] = 1
        except ZeroDivisionError:
            _error_code = 10

        _n_yes = sum(module.lst_sftw_quality[0][:8]) + \
                 sum(module.lst_sftw_quality[0][12:]) + \
                 sum(_ratios)
        module.dr = (25.0 - _n_yes) / 25.0

    elif module.phase_id == 3:              # Preliminary design review
        _ratios = [0, 0, 0, 0, 0]
        try:
            if(module.lst_sftw_quality[1][3] /
               (module.lst_sftw_quality[1][2] +
                module.lst_sftw_quality[1][3])) <= 0.3:
                _ratios[0] = 1
            if(module.lst_sftw_quality[1][7] /
               module.lst_sftw_quality[1][6]) > 0.5:
                _ratios[1] = 1
            if(module.lst_sftw_quality[1][9] /
               module.lst_sftw_quality[1][8]) > 0.5:
                _ratios[2] = 1
            if(module.lst_sftw_quality[1][11] /
               module.lst_sftw_quality[1][10]) > 0.5:
                _ratios[3] = 1
            if(module.lst_sftw_quality[1][15] /
               module.lst_sftw_quality[1][14]) > 0.75:
                _ratios[4] = 1
        except ZeroDivisionError:
            _error_code = 10

        _n_yes = sum(module.lst_sftw_quality[1][:2]) + \
                 sum(module.lst_sftw_quality[1][4:6]) + \
                 sum(module.lst_sftw_quality[1][12:14]) + \
                 sum(module.lst_sftw_quality[1][16:24]) + \
                 sum(_ratios)
        module.dr = (19.0 - _n_yes) / 19.0

    if module.dr < 0.5:                     # High risk
        module.sq = 1.1
    else:
        module.sq = 1.0

    return _error_code