looptools.counter   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 41
Duplicated Lines 97.56 %

Importance

Changes 0
Metric Value
wmc 10
eloc 29
dl 40
loc 41
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A Counter.total() 4 4 1
A Counter.up() 5 5 1
A Counter.__init__() 8 8 1
A Counter.__repr__() 2 2 1
B Counter.leading_zeros() 16 16 6

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 View Code Duplication
class Counter:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
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