pystratum_mysql.wrapper.create_routine_wrapper()   D
last analyzed

Complexity

Conditions 13

Size

Total Lines 37
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 163.2223

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 37
ccs 1
cts 26
cp 0.0385
rs 4.2
c 0
b 0
f 0
cc 13
nop 2
crap 163.2223

How to fix   Complexity   

Complexity

Complex classes like pystratum_mysql.wrapper.create_routine_wrapper() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1 1
from typing import Any, Dict
2
3 1
from pystratum_mysql.wrapper.MySqlBulkWrapper import MySqlBulkWrapper
4 1
from pystratum_mysql.wrapper.MySqlFunctionsWrapper import MySqlFunctionsWrapper
5 1
from pystratum_mysql.wrapper.MySqlLogWrapper import MySqlLogWrapper
6 1
from pystratum_mysql.wrapper.MySqlMultiWrapper import MySqlMultiWrapper
7 1
from pystratum_mysql.wrapper.MySqlNoneWrapper import MySqlNoneWrapper
8 1
from pystratum_mysql.wrapper.MySqlRow0Wrapper import MySqlRow0Wrapper
9 1
from pystratum_mysql.wrapper.MySqlRow1Wrapper import MySqlRow1Wrapper
10 1
from pystratum_mysql.wrapper.MySqlRowsWithIndexWrapper import MySqlRowsWithIndexWrapper
11 1
from pystratum_mysql.wrapper.MySqlRowsWithKeyWrapper import MySqlRowsWithKeyWrapper
12 1
from pystratum_mysql.wrapper.MySqlRowsWrapper import MySqlRowsWrapper
13 1
from pystratum_mysql.wrapper.MySqlSingleton0Wrapper import MySqlSingleton0Wrapper
14 1
from pystratum_mysql.wrapper.MySqlSingleton1Wrapper import MySqlSingleton1Wrapper
15
# ----------------------------------------------------------------------------------------------------------------------
16
from pystratum_mysql.wrapper.MySqlWrapper import MySqlWrapper
17
18 1
19
def create_routine_wrapper(routine: Dict[str, Any], lob_as_string_flag: bool) -> MySqlWrapper:
20
    """
21 1
    A factory for creating the appropriate object for generating a wrapper method for a stored routine.
22
23
    :param dict[str,str] routine: The metadata of the sored routine.
24
    :param bool lob_as_string_flag: If True BLOBs and CLOBs must be treated as strings.
25
26
    :rtype: MySqlWrapper
27
    """
28
    if routine['designation'] == 'bulk':
29
        wrapper = MySqlBulkWrapper(routine, lob_as_string_flag)
30
    elif routine['designation'] == 'function':
31
        wrapper = MySqlFunctionsWrapper(routine, lob_as_string_flag)
32
    elif routine['designation'] == 'log':
33
        wrapper = MySqlLogWrapper(routine, lob_as_string_flag)
34
    elif routine['designation'] == 'multi':
35
        wrapper = MySqlMultiWrapper(routine, lob_as_string_flag)
36
    elif routine['designation'] == 'none':
37
        wrapper = MySqlNoneWrapper(routine, lob_as_string_flag)
38
    elif routine['designation'] == 'row0':
39
        wrapper = MySqlRow0Wrapper(routine, lob_as_string_flag)
40
    elif routine['designation'] == 'row1':
41
        wrapper = MySqlRow1Wrapper(routine, lob_as_string_flag)
42
    elif routine['designation'] == 'rows_with_index':
43
        wrapper = MySqlRowsWithIndexWrapper(routine, lob_as_string_flag)
44
    elif routine['designation'] == 'rows_with_key':
45
        wrapper = MySqlRowsWithKeyWrapper(routine, lob_as_string_flag)
46
    elif routine['designation'] == 'rows':
47
        wrapper = MySqlRowsWrapper(routine, lob_as_string_flag)
48
    elif routine['designation'] == 'singleton0':
49
        wrapper = MySqlSingleton0Wrapper(routine, lob_as_string_flag)
50
    elif routine['designation'] == 'singleton1':
51
        wrapper = MySqlSingleton1Wrapper(routine, lob_as_string_flag)
52
    else:
53
        raise Exception("Unknown routine type '{0!s}'.".format(routine['designation']))
54
55
    return wrapper
56
57
# ----------------------------------------------------------------------------------------------------------------------
58