Total Complexity | 4 |
Total Lines | 36 |
Duplicated Lines | 100 % |
Coverage | 52.17% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
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 | 1 | from plugin.preferences.options.core.base import SimpleOption |
|
12 | 1 | View Code Duplication | class SyncIdleDelayOption(SimpleOption): |
|
|||
13 | 1 | key = 'sync.idle_delay' |
|
14 | 1 | type = 'enum' |
|
15 | |||
16 | 1 | choices = IDLE_DELAY_LABELS_BY_KEY |
|
17 | 1 | default = SyncIdleDelay.M30 |
|
18 | 1 | scope = 'server' |
|
19 | |||
20 | 1 | group = ('Advanced', 'Sync - Triggers') |
|
21 | 1 | label = 'Idle delay' |
|
22 | 1 | order = 131 |
|
23 | |||
24 | 1 | preference = 'sync_idle_delay' |
|
25 | |||
26 | 1 | def on_database_changed(self, value, account=None): |
|
27 | if value not in IDLE_DELAY_IDS_BY_KEY: |
||
28 | log.warn('Unknown value: %r', value) |
||
29 | return |
||
30 | |||
31 | # Map `value` to plex preference |
||
32 | value = IDLE_DELAY_IDS_BY_KEY[value] |
||
33 | |||
34 | # Update preference |
||
35 | return self._update_preference(value, account) |
||
36 | |||
37 | 1 | def on_plex_changed(self, value, account=None): |
|
38 | if value not in IDLE_DELAY_KEYS_BY_LABEL: |
||
39 | log.warn('Unknown value: %r', value) |
||
40 | return |
||
41 | |||
42 | # Map plex `value` |
||
43 | value = IDLE_DELAY_KEYS_BY_LABEL[value] |
||
44 | |||
45 | # Update database |
||
46 | self.update(value, account, emit=False) |
||
47 | return value |
||
48 |