Completed
Push — master ( b95acc...a5fbcd )
by Oleksandr
01:06
created

Logging   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 30
Duplicated Lines 100 %

Test Coverage

Coverage 85.71%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 1
c 4
b 0
f 0
dl 30
loc 30
ccs 6
cts 7
cp 0.8571
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A from_ini() 14 14 1

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, IntType, BooleanType
7 1
from schematics.types.compound import ModelType
8
9 1
from .interfaces import INISerializable
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
class Logging(Model):
14 1
    file_name = StringType(
15
        default="eventlog.lst",
16
        min_length=1,
17
        required=True,
18
    )
19 1
    keep = BooleanType(
20
        default=True,
21
        required=True,
22
    )
23 1
    log_buildings = BooleanType(
24
        default=False,
25
        required=True,
26
    )
27
28 1
    @classmethod
29
    def from_ini(cls, ini):
30
        return cls({
31
            'file_name': ini.get(
32
                'game', 'eventlog',
33
                fallback=cls.file_name.default,
34
            ),
35
            'keep': ini.getboolean(
36
                'game', 'eventlogkeep',
37
                fallback=cls.keep.default,
38
            ),
39
            'log_buildings': ini.getboolean(
40
                'game', 'eventlogHouse',
41
                fallback=cls.log_buildings.default,
42
            ),
43
        })
44
45
46 1
@zope.interface.implementer(INISerializable)
47 1
class Events(Model):
48 1
    chat_level = IntType(
49
        min_value=0,
50
        max_value=3,
51
        default=0,
52
        required=True,
53
    )
54 1
    logging = ModelType(
55
        model_spec=Logging,
56
        required=True,
57
    )
58
59 1
    @classmethod
60
    def from_ini(cls, ini):
61
        return cls({
62
            'chat_level': ini.getint(
63
                'chat', 'autoLogDetail',
64
                fallback=cls.chat_level.default,
65
            ),
66
            'logging': Logging.from_ini(ini),
67
        })
68