Refly   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 69
Duplicated Lines 100 %

Test Coverage

Coverage 80%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 6
c 4
b 0
f 1
dl 69
loc 69
ccs 8
cts 10
cp 0.8
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B from_ini() 27 27 2
A default() 5 5 2
A to_ini() 11 11 2

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
# coding: utf-8
2
3 1
import zope.interface
4
5 1
from schematics.models import Model
6 1
from schematics.types import BooleanType, IntType, FloatType
7
8 1
from .constants import NO_DEATH_LIMIT_FLAG
9 1
from .helpers import field_from_ini, field_to_ini
10
from .interfaces import INISerializable, DefaultProvider
11
12 1
13 1 View Code Duplication
@zope.interface.implementer(INISerializable)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
14 1
@zope.interface.implementer(DefaultProvider)
15 1
class Refly(Model):
16
    enabled = BooleanType(
17
        default=True,
18
        required=True,
19 1
    )
20
    death_penalty = IntType(
21
        min_value=0,
22
        default=0,
23
        required=True,
24 1
    )
25
    death_penalty_multiplier = FloatType(
26
        min_value=0.0,
27
        default=0.0,
28
        required=True,
29 1
    )
30
    death_limit = IntType(
31
        min_value=1,
32
        default=None,
33
        required=False,
34
    )
35 1
36
    @classmethod
37
    def from_ini(cls, ini):
38
        death_limit = field_from_ini(
39
            cls.death_limit, ini,
40
            'NET', 'maxAllowedKIA',
41
        )
42
        death_limit = (
43
            None
44
            if death_limit == NO_DEATH_LIMIT_FLAG
45
            else death_limit
46
        )
47
48
        return cls({
49
            'enabled': not field_from_ini(
50
                cls.enabled, ini,
51
                'NET', 'reflyDisabled',
52
                False,
53
            ),
54
            'death_penalty': field_from_ini(
55
                cls.death_penalty, ini,
56 1
                'NET', 'reflyKIADelay',
57
            ),
58
            'death_penalty_multiplier': field_from_ini(
59
                cls.death_penalty_multiplier, ini,
60
                'NET', 'reflyKIADelayMultiplier',
61
            ),
62
            'death_limit': death_limit,
63
        })
64
65
    def to_ini(self, ini):
66
        death_limit = (
67
            NO_DEATH_LIMIT_FLAG
68
            if self.death_limit is None
69
            else self.death_limit
70
        )
71
72
        field_to_ini(not self.enabled, ini, 'NET', 'reflyDisabled')
73
        field_to_ini(self.death_penalty, ini, 'NET', 'reflyKIADelay')
74
        field_to_ini(self.death_penalty_multiplier, ini, 'NET', 'reflyKIADelayMultiplier')
75
        field_to_ini(death_limit, ini, 'NET', 'maxAllowedKIA')
76
77
    @classmethod
78
    def default(cls):
79
        return cls({
80
            field_name: field.default
81
            for field_name, field in cls.fields.items()
82
        })
83