| Total Complexity | 4 |
| Total Lines | 45 |
| Duplicated Lines | 100 % |
| Coverage | 80% |
| Changes | 3 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 12 | 1 | View Code Duplication | @zope.interface.implementer(INISerializable) |
|
|
|||
| 13 | 1 | @zope.interface.implementer(DefaultProvider) |
|
| 14 | 1 | class HUD(Model): |
|
| 15 | 1 | show_mission_info = BooleanType( |
|
| 16 | default=True, |
||
| 17 | required=True, |
||
| 18 | ) |
||
| 19 | 1 | show_kill_info = BooleanType( |
|
| 20 | default=True, |
||
| 21 | required=True, |
||
| 22 | ) |
||
| 23 | 1 | show_at_bottom = BooleanType( |
|
| 24 | default=False, |
||
| 25 | required=True, |
||
| 26 | ) |
||
| 27 | |||
| 28 | 1 | @classmethod |
|
| 29 | def from_ini(cls, ini): |
||
| 30 | return cls({ |
||
| 31 | 'show_mission_info': not field_from_ini( |
||
| 32 | cls.show_mission_info, ini, |
||
| 33 | 'game', 'NoMissionInfoHud', |
||
| 34 | False, |
||
| 35 | ), |
||
| 36 | 'show_kill_info': not field_from_ini( |
||
| 37 | cls.show_kill_info, ini, |
||
| 38 | 'game', 'noKillInfoHud', |
||
| 39 | False, |
||
| 40 | ), |
||
| 41 | 'show_at_bottom': field_from_ini( |
||
| 42 | cls.show_at_bottom, ini, |
||
| 43 | 'game', 'lowInfoHud', |
||
| 44 | ), |
||
| 45 | 1 | }) |
|
| 46 | |||
| 47 | def to_ini(self, ini): |
||
| 48 | field_to_ini(not self.show_mission_info, ini, 'game', 'NoMissionInfoHud') |
||
| 49 | field_to_ini(not self.show_kill_info, ini, 'game', 'noKillInfoHud') |
||
| 50 | field_to_ini(self.show_at_bottom, ini, 'game', 'lowInfoHud') |
||
| 51 | |||
| 52 | @classmethod |
||
| 53 | def default(cls): |
||
| 54 | return cls({ |
||
| 55 | field_name: field.default |
||
| 56 | for field_name, field in cls.fields.items() |
||
| 57 | }) |
||
| 58 |