Passed
Push — master ( 694e2f...150a8e )
by Dean
09:10 queued 06:18
created

SyncWatchedOption   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 100 %

Test Coverage

Coverage 52.17%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
dl 54
loc 54
ccs 12
cts 23
cp 0.5217
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A on_plex_changed() 11 11 2
A on_database_changed() 10 10 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 1
from plugin.core.environment import translate as _
0 ignored issues
show
Bug introduced by
The name environment does not seem to exist in module plugin.core.
Loading history...
Configuration introduced by
Unable to import 'plugin.core.environment' (invalid syntax (<string>, line 101))

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
2 1
from plugin.preferences.options.core.base import SimpleOption
3 1
from plugin.preferences.options.core.description import Description
4 1
from plugin.preferences.options.o_sync.constants import MODE_KEYS_BY_LABEL, MODE_LABELS_BY_KEY, MODE_IDS_BY_KEY
5 1
from plugin.sync.core.enums import SyncMode
6
7 1
import logging
8
9 1
log = logging.getLogger(__name__)
10
11
12 1 View Code Duplication
class SyncWatchedOption(SimpleOption):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
13 1
    key = 'sync.watched.mode'
14 1
    type = 'enum'
15
16 1
    choices = MODE_LABELS_BY_KEY
17 1
    default = SyncMode.Full
18
19 1
    group = (_('Sync'), _('Watched'))
20 1
    label = _('Mode')
21 1
    description = Description(
22
        _("Syncing mode for movie and episode watched states *(applies to both automatic and manual syncs)*."), [
23
            (_("Full"), _(
24
                "Synchronize watched states with your Trakt.tv profile"
25
            )),
26
            (_("Pull"), _(
27
                "Only pull watched states from your Trakt.tv profile"
28
            )),
29
            (_("Push"), _(
30
                "Only push watched states to your Trakt.tv profile"
31
            )),
32
            (_("Fast Pull"), _(
33
                "Only pull changes to watched states from your Trakt.tv profile"
34
            )),
35
            (_("Disabled"), _(
36
                "Completely disable syncing of watched states"
37
            ))
38
        ]
39
    )
40 1
    order = 200
41
42 1
    preference = 'sync_watched'
43
44 1
    def on_database_changed(self, value, account=None):
45
        if value not in MODE_IDS_BY_KEY:
46
            log.warn('Unknown value: %r', value)
47
            return
48
49
        # Map `value` to plex preference
50
        value = MODE_IDS_BY_KEY[value]
51
52
        # Update preference
53
        return self._update_preference(value, account)
54
55 1
    def on_plex_changed(self, value, account=None):
56
        if value not in MODE_KEYS_BY_LABEL:
57
            log.warn('Unknown value: %r', value)
58
            return
59
60
        # Map plex `value`
61
        value = MODE_KEYS_BY_LABEL[value]
62
63
        # Update database
64
        self.update(value, account, emit=False)
65
        return value
66