PyDMXControl.profiles.Stairville._Quad_Par_Profile   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 84
Duplicated Lines 29.76 %

Importance

Changes 0
Metric Value
wmc 8
eloc 57
dl 25
loc 84
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A Quad_Par_Profile.__init__() 0 16 5
A Quad_Par_Profile_4.__init__() 11 11 1
A Quad_Par_Profile_6.__init__() 14 14 1
A Quad_Par_Profile_8.__init__() 0 16 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
"""
2
 *  PyDMXControl: A Python 3 module to control DMX using OpenDMX or uDMX.
3
 *                Featuring fixture profiles, built-in effects and a web control panel.
4
 *  <https://github.com/MattIPv4/PyDMXControl/>
5
 *  Copyright (C) 2018 Matt Cowley (MattIPv4) ([email protected])
6
"""
7
8
from warnings import warn
9
10
from ..defaults import Fixture, Vdim
11
12
13
class Quad_Par_Profile_4(Vdim):
14
15 View Code Duplication
    def __init__(self, *args, **kwargs):
16
        super().__init__(*args, **kwargs)
17
18
        self._register_channel('red', vdim=True)
19
        self._register_channel_aliases('red', 'r')
20
        self._register_channel('green', vdim=True)
21
        self._register_channel_aliases('green', 'g')
22
        self._register_channel('blue', vdim=True)
23
        self._register_channel_aliases('blue', 'b')
24
        self._register_channel('white', vdim=True)
25
        self._register_channel_aliases('white', 'w')
26
27
28
class Quad_Par_Profile_6(Fixture):
29
30 View Code Duplication
    def __init__(self, *args, **kwargs):
31
        super().__init__(*args, **kwargs)
32
33
        self._register_channel('red')
34
        self._register_channel_aliases('red', 'r')
35
        self._register_channel('green')
36
        self._register_channel_aliases('green', 'g')
37
        self._register_channel('blue')
38
        self._register_channel_aliases('blue', 'b')
39
        self._register_channel('white')
40
        self._register_channel_aliases('white', 'w')
41
        self._register_channel('strobe')
42
        self._register_channel('dimmer')
43
        self._register_channel_aliases('dimmer', 'dim', 'd')
44
45
46
class Quad_Par_Profile_8(Fixture):
47
48
    def __init__(self, *args, **kwargs):
49
        super().__init__(*args, **kwargs)
50
51
        self._register_channel('dimmer')
52
        self._register_channel_aliases('dimmer', 'dim', 'd')
53
        self._register_channel('red')
54
        self._register_channel_aliases('red', 'r')
55
        self._register_channel('green')
56
        self._register_channel_aliases('green', 'g')
57
        self._register_channel('blue')
58
        self._register_channel_aliases('blue', 'b')
59
        self._register_channel('white')
60
        self._register_channel_aliases('white', 'w')
61
        self._register_channel('mode')
62
        self._register_channel('function')
63
        self._register_channel('strobe')
64
65
66
class Quad_Par_Profile(Fixture):
67
68
    def __init__(self, *args, **kwargs):
69
        super().__init__(*args, **kwargs)
70
71
        modes = [4, 6, 8]
72
        if 'mode' not in kwargs or kwargs['mode'] not in modes:
73
            kwargs['mode'] = modes[-1]
74
            warn('No/invalid mode keyword argument given, default mode {} applied.'.format(kwargs['mode']))
75
76
        if kwargs['mode'] == 4:
77
            new = Quad_Par_Profile_4(*args, **kwargs)
78
        elif kwargs['mode'] == 6:
79
            new = Quad_Par_Profile_6(*args, **kwargs)
80
        else:
81
            new = Quad_Par_Profile_8(*args, **kwargs)
82
83
        self.__dict__ = new.__dict__
84