pystratum_pgsql.wrapper.create_routine_wrapper()   D
last analyzed

Complexity

Conditions 12

Size

Total Lines 39
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 22
CRAP Score 12.2487

Importance

Changes 0
Metric Value
cc 12
eloc 25
nop 2
dl 0
loc 39
ccs 22
cts 25
cp 0.88
crap 12.2487
rs 4.8
c 0
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like pystratum_pgsql.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
"""
2
PyStratum
3
"""
4 1
from typing import Dict
5
6 1
from pystratum_pgsql.wrapper.PgSqlFunctionsWrapper import PgSqlFunctionsWrapper
7 1
from pystratum_pgsql.wrapper.PgSqlLogWrapper import PgSqlLogWrapper
8 1
from pystratum_pgsql.wrapper.PgSqlNoneWrapper import PgSqlNoneWrapper
9 1
from pystratum_pgsql.wrapper.PgSqlRow0Wrapper import PgSqlRow0Wrapper
10 1
from pystratum_pgsql.wrapper.PgSqlRow1Wrapper import PgSqlRow1Wrapper
11 1
from pystratum_pgsql.wrapper.PgSqlRowsWithIndexWrapper import PgSqlRowsWithIndexWrapper
12 1
from pystratum_pgsql.wrapper.PgSqlRowsWithKeyWrapper import PgSqlRowsWithKeyWrapper
13 1
from pystratum_pgsql.wrapper.PgSqlRowsWrapper import PgSqlRowsWrapper
14 1
from pystratum_pgsql.wrapper.PgSqlSingleton0Wrapper import PgSqlSingleton0Wrapper
15 1
from pystratum_pgsql.wrapper.PgSqlSingleton1Wrapper import PgSqlSingleton1Wrapper
16 1
from pystratum_pgsql.wrapper.PgSqlTableWrapper import PgSqlTableWrapper
17 1
from pystratum_pgsql.wrapper.PgSqlWrapper import PgSqlWrapper
18
19
20 1
def create_routine_wrapper(routine: Dict, lob_as_string_flag: bool) -> PgSqlWrapper:
21
    """
22
    A factory for creating the appropriate object for generating a wrapper method for a stored routine.
23
24
    :param dict[str,str] routine: The metadata of the sored routine.
25
    :param bool lob_as_string_flag: If True BLOBs and CLOBs must be treated as strings.
26
27
    :rtype: PgSqlWrapper
28
    """
29 1
    if routine['designation'] == 'none':
30 1
        wrapper = PgSqlNoneWrapper(routine, lob_as_string_flag)
31 1
    elif routine['designation'] == 'row0':
32 1
        wrapper = PgSqlRow0Wrapper(routine, lob_as_string_flag)
33 1
    elif routine['designation'] == 'row1':
34 1
        wrapper = PgSqlRow1Wrapper(routine, lob_as_string_flag)
35 1
    elif routine['designation'] == 'rows':
36 1
        wrapper = PgSqlRowsWrapper(routine, lob_as_string_flag)
37 1
    elif routine['designation'] == 'rows_with_index':
38 1
        wrapper = PgSqlRowsWithIndexWrapper(routine, lob_as_string_flag)
39 1
    elif routine['designation'] == 'rows_with_key':
40 1
        wrapper = PgSqlRowsWithKeyWrapper(routine, lob_as_string_flag)
41 1
    elif routine['designation'] == 'singleton0':
42 1
        wrapper = PgSqlSingleton0Wrapper(routine, lob_as_string_flag)
43 1
    elif routine['designation'] == 'singleton1':
44 1
        wrapper = PgSqlSingleton1Wrapper(routine, lob_as_string_flag)
45 1
    elif routine['designation'] == 'function':
46 1
        wrapper = PgSqlFunctionsWrapper(routine, lob_as_string_flag)
47 1
    elif routine['designation'] == 'log':
48 1
        wrapper = PgSqlLogWrapper(routine, lob_as_string_flag)
49
    elif routine['designation'] == 'table':
50
        wrapper = PgSqlTableWrapper(routine, lob_as_string_flag)
51
    # elif routine['designation'] == 'bulk':
52
    #    wrapper = BulkWrapper(routine, lob_as_string_flag)
53
    # elif routine['designation'] == 'bulk_insert':
54
    #    wrapper = BulkInsertWrapper(routine, lob_as_string_flag)
55
    else:
56
        raise Exception("Unknown routine type '{0!s}'.".format(routine['designation']))
57
58 1
    return wrapper
59
60
# ----------------------------------------------------------------------------------------------------------------------
61