sdoc.sdoc1.data_type.IntegerDataType   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 89
Duplicated Lines 93.26 %

Test Coverage

Coverage 79.17%

Importance

Changes 0
Metric Value
wmc 10
eloc 24
dl 83
loc 89
ccs 19
cts 24
cp 0.7917
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A IntegerDataType.get_type_id() 5 5 1
A IntegerDataType.is_true() 5 5 1
A IntegerDataType.is_scalar() 5 5 1
A IntegerDataType.__init__() 8 8 1
A IntegerDataType.is_constant() 5 5 1
A IntegerDataType.debug() 7 7 1
A IntegerDataType.__str__() 5 5 1
A IntegerDataType.dereference() 7 7 1
A IntegerDataType.get_value() 5 5 1
A IntegerDataType.is_defined() 5 5 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
from typing import Union
2
3 1
from sdoc.sdoc1.data_type.DataType import DataType
4
5
6 1 View Code Duplication
class IntegerDataType(DataType):
7
    """
8
    Class for integer data types.
9
    """
10
11
    # ------------------------------------------------------------------------------------------------------------------
12 1
    def __init__(self, value: Union[int, str]):
13
        """
14
        Object constructor.
15
16
        :param int|str value: The value of this integer constant.
17
        """
18 1
        self._value: int = int(value)
19 1
        """
20
        The value of this constant integer.
21
        """
22
23
    # ------------------------------------------------------------------------------------------------------------------
24 1
    def debug(self, indent: int = 0) -> str:
25
        """
26
        Returns a string for debugging.
27
28
        :param int indent: Unused.
29
        """
30 1
        return str(self._value)
31
32
    # ------------------------------------------------------------------------------------------------------------------
33 1
    def dereference(self):
34
        """
35
        Returns a clone of this integer.
36
37
        :rtype: sdoc.sdoc1.data_type.IntegerDataType.IntegerDataType
38
        """
39 1
        return IntegerDataType(self._value)
40
41
    # ------------------------------------------------------------------------------------------------------------------
42 1
    def get_value(self) -> int:
43
        """
44
        Returns the underling value of this data type.
45
        """
46 1
        return self._value
47
48
    # ------------------------------------------------------------------------------------------------------------------
49 1
    def get_type_id(self) -> int:
50
        """
51
        Returns the ID of this data type.
52
        """
53
        return DataType.INT
54
55
    # ------------------------------------------------------------------------------------------------------------------
56 1
    def is_constant(self) -> bool:
57
        """
58
        Returns False always.
59
        """
60
        return False
61
62
    # ------------------------------------------------------------------------------------------------------------------
63 1
    def is_defined(self) -> bool:
64
        """
65
        Returns True always.
66
        """
67 1
        return True
68
69
    # ------------------------------------------------------------------------------------------------------------------
70 1
    def is_scalar(self) -> bool:
71
        """
72
        Returns True always.
73
        """
74
        return False
75
76
    # ------------------------------------------------------------------------------------------------------------------
77 1
    def is_true(self) -> bool:
78
        """
79
        Returns True if this integer is not 0. Returns False otherwise.
80
        """
81
        return self._value != 0
82
83
    # ------------------------------------------------------------------------------------------------------------------
84 1
    def __str__(self) -> str:
85
        """
86
        Returns the string representation of the integer constant.
87
        """
88
        return str(self._value)
89
90
# ----------------------------------------------------------------------------------------------------------------------
91