sdoc.helper.SDoc   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 50
Duplicated Lines 92 %

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
wmc 2
eloc 13
dl 46
loc 50
ccs 8
cts 12
cp 0.6667
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A SDoc.escape() 19 19 1
A SDoc.unescape() 19 19 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1 1
import re
2
3
4 1 View Code Duplication
class SDoc:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
5
    """
6
    Utility class with functions for generating SDoc code.
7
    """
8
9
    # ------------------------------------------------------------------------------------------------------------------
10 1
    @staticmethod
11 1
    def escape(text: str) -> str:
12
        """
13
        Returns an escaped string that is safe to use in SDoc.
14
15
        :param str text: The escaped string.
16
        """
17
18 1
        def replace(match_obj):
19
            """
20
            Returns the match text prefixed with backslash
21
22
            :param re.match match_obj: The match.
23
24
            :rtype: str
25
            """
26
            return '\\' + match_obj.group(0)
27
28 1
        return re.sub(r'[\\{}]', replace, text)
29
30
    # ------------------------------------------------------------------------------------------------------------------
31 1
    @staticmethod
32 1
    def unescape(text: str) -> str:
33
        """
34
        Returns an unescaped SDoc escaped string. I.e. removes back slashes.
35
36
        :param str text: The SDoc escaped string.
37
        """
38
39
        def replace(match_obj):
40
            """
41
            Returns the match text without prefixed backslash.
42
43
            :param re.match match_obj: The match.
44
45
            :rtype: str
46
            """
47
            return match_obj.group(0)[1:]
48
49
        return re.sub(r'\\.', replace, text)
50
51
# ----------------------------------------------------------------------------------------------------------------------
52