compare_strings()   C
last analyzed

Complexity

Conditions 11

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 11
eloc 9
nop 2
dl 0
loc 13
rs 5.4
c 0
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like osm_poi_matchmaker.libs.compare_strings.compare_strings() 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
# -*- coding: utf-8 -*-
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
3
try:
4
    import logging
5
    import sys
6
    import re
0 ignored issues
show
Unused Code introduced by
The import re seems to be unused.
Loading history...
7
except ImportError as err:
8
    logging.error('Error %s import module: %s', __name__, err)
9
    logging.exception('Exception occurred')
10
11
    sys.exit(128)
12
13
14
def compare_strings(string1, string2=''):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Unused Code introduced by
Either all return statements in a function should return an expression, or none of them should.
Loading history...
15
    # New string
16
    if (string1 is '' or string1 is None) and (string2 is not '' and string2 is not None):
0 ignored issues
show
unused-code introduced by
Unnecessary "elif" after "return"
Loading history...
introduced by
Comparison to literal
Loading history...
17
        return 'N'
18
    # Deleted string
19
    elif (string1 is not '' and string1 is not None) and (string2 is '' or string2 is None):
0 ignored issues
show
introduced by
Comparison to literal
Loading history...
20
        return 'D'
21
    # Modified string
22
    elif str(string1) != str(string2):
23
        return 'M'
24
    # Equal string
25
    elif str(string1) == str(string2):
26
        return 'E'
27