About   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 100 %

Test Coverage

Coverage 77.78%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 4
c 3
b 0
f 1
dl 34
loc 34
ccs 7
cts 9
cp 0.7778
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A from_ini() 10 10 1
A to_ini() 3 3 1
A default() 5 5 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 StringType
7
8 1
from .interfaces import INISerializable, DefaultProvider
9 1
from .helpers import field_from_ini, field_to_ini
10
11
12 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...
13 1
@zope.interface.implementer(DefaultProvider)
14 1
class About(Model):
15 1
    name = StringType(
16
        default="",
17
        required=True,
18
    )
19 1
    description = StringType(
20
        default="",
21
        required=True,
22
    )
23
24 1
    @classmethod
25
    def from_ini(cls, ini):
26
        return cls({
27
            'name': field_from_ini(
28
                cls.name, ini,
29
                'NET', 'serverName',
30
            ),
31
            'description': field_from_ini(
32
                cls.description, ini,
33
                'NET', 'serverDescription',
34
            ),
35
        })
36
37 1
    def to_ini(self, ini):
38
        field_to_ini(self.name, ini, 'NET', 'serverName')
39
        field_to_ini(self.description, ini, 'NET', 'serverDescription')
40
41
    @classmethod
42
    def default(cls):
43
        return cls({
44
            field_name: field.default
45
            for field_name, field in cls.fields.items()
46
        })
47