| Total Complexity | 10 |
| Total Lines | 41 |
| Duplicated Lines | 97.56 % |
| Changes | 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 | View Code Duplication | class Counter: |
|
|
|
|||
| 2 | def __init__(self, length=0): |
||
| 3 | """ |
||
| 4 | Counts number of iterations in a process. |
||
| 5 | :param length: Minimum string length of a returned count. Example - with a length of 3 the first count would |
||
| 6 | return '001'. |
||
| 7 | """ |
||
| 8 | self.counter = 0 |
||
| 9 | self.length = length |
||
| 10 | |||
| 11 | def __repr__(self): |
||
| 12 | print(str(self.counter)) |
||
| 13 | |||
| 14 | def leading_zeros(self): |
||
| 15 | if self.length == 3: |
||
| 16 | if self.counter < 10: |
||
| 17 | count = "00" + str(self.counter) |
||
| 18 | elif 9 < self.counter < 100: |
||
| 19 | count = "0" + str(self.counter) |
||
| 20 | else: |
||
| 21 | count = self.counter |
||
| 22 | elif self.length == 2: |
||
| 23 | if self.counter < 10: |
||
| 24 | count = "0" + str(self.counter) |
||
| 25 | else: |
||
| 26 | count = self.counter |
||
| 27 | else: |
||
| 28 | count = self.counter |
||
| 29 | return count |
||
| 30 | |||
| 31 | @property |
||
| 32 | def up(self): |
||
| 33 | self.counter += 1 |
||
| 34 | count = self.leading_zeros() |
||
| 35 | return str(count) |
||
| 36 | |||
| 37 | @property |
||
| 38 | def total(self): |
||
| 39 | count = self.leading_zeros() |
||
| 40 | return str(count) |
||
| 41 |