| Total Complexity | 10 |
| Total Lines | 101 |
| Duplicated Lines | 100 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
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 | """ |
||
| 12 | View Code Duplication | class IntegerDataType(DataType): |
|
|
1 ignored issue
–
show
|
|||
| 13 | """ |
||
| 14 | Class for integer data types. |
||
| 15 | """ |
||
| 16 | |||
| 17 | # ------------------------------------------------------------------------------------------------------------------ |
||
| 18 | def __init__(self, value): |
||
| 19 | """ |
||
| 20 | Object constructor. |
||
| 21 | |||
| 22 | :param int|str value: The value of this integer constant. |
||
| 23 | """ |
||
| 24 | self._value = int(value) |
||
| 25 | """ |
||
| 26 | The value of this constant integer. |
||
| 27 | |||
| 28 | :type: int |
||
| 29 | """ |
||
| 30 | |||
| 31 | # ------------------------------------------------------------------------------------------------------------------ |
||
| 32 | def debug(self, indent=0): |
||
| 33 | """ |
||
| 34 | Returns a string for debugging. |
||
| 35 | |||
| 36 | :param int indent: Unused. |
||
| 37 | |||
| 38 | :rtype: str |
||
| 39 | """ |
||
| 40 | return str(self._value) |
||
| 41 | |||
| 42 | # ------------------------------------------------------------------------------------------------------------------ |
||
| 43 | def dereference(self): |
||
| 44 | """ |
||
| 45 | Returns a clone of this integer. |
||
| 46 | |||
| 47 | :rtype: IntegerDataType |
||
| 48 | """ |
||
| 49 | return IntegerDataType(self._value) |
||
| 50 | |||
| 51 | # ------------------------------------------------------------------------------------------------------------------ |
||
| 52 | def get_value(self): |
||
| 53 | """ |
||
| 54 | Returns the underling value of this data type. |
||
| 55 | |||
| 56 | :rtype: int |
||
| 57 | """ |
||
| 58 | return self._value |
||
| 59 | |||
| 60 | # ------------------------------------------------------------------------------------------------------------------ |
||
| 61 | def get_type_id(self): |
||
| 62 | """ |
||
| 63 | Returns the ID of this data type. |
||
| 64 | |||
| 65 | :rtype: int |
||
| 66 | """ |
||
| 67 | return DataType.INT |
||
| 68 | |||
| 69 | # ------------------------------------------------------------------------------------------------------------------ |
||
| 70 | def is_constant(self): |
||
| 71 | """ |
||
| 72 | Returns False always. |
||
| 73 | |||
| 74 | :rtype: bool |
||
| 75 | """ |
||
| 76 | return False |
||
| 77 | |||
| 78 | # ------------------------------------------------------------------------------------------------------------------ |
||
| 79 | def is_defined(self): |
||
| 80 | """ |
||
| 81 | Returns True always. |
||
| 82 | |||
| 83 | :rtype: bool |
||
| 84 | """ |
||
| 85 | return True |
||
| 86 | |||
| 87 | # ------------------------------------------------------------------------------------------------------------------ |
||
| 88 | def is_scalar(self): |
||
| 89 | """ |
||
| 90 | Returns True always. |
||
| 91 | |||
| 92 | :rtype: bool |
||
| 93 | """ |
||
| 94 | return False |
||
| 95 | |||
| 96 | # ------------------------------------------------------------------------------------------------------------------ |
||
| 97 | def is_true(self): |
||
| 98 | """ |
||
| 99 | Returns True if this integer is not 0. Returns False otherwise. |
||
| 100 | |||
| 101 | :rtype: bool |
||
| 102 | """ |
||
| 103 | return self._value != 0 |
||
| 104 | |||
| 105 | # ------------------------------------------------------------------------------------------------------------------ |
||
| 106 | def __str__(self): |
||
| 107 | """ |
||
| 108 | Returns the string representation of the integer constant. |
||
| 109 | |||
| 110 | :rtype: str |
||
| 111 | """ |
||
| 112 | return str(self._value) |
||
| 113 | |||
| 115 |