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

SyncListsWatchlistOption   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 100 %

Test Coverage

Coverage 52.17%

Importance

Changes 0
Metric Value
wmc 4
c 0
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_database_changed() 10 10 2
A on_plex_changed() 11 11 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
6 1
import logging
7
8 1
log = logging.getLogger(__name__)
9
10
11 1 View Code Duplication
class SyncListsWatchlistOption(SimpleOption):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
12 1
    key = 'sync.lists.watchlist.mode'
13 1
    type = 'enum'
14
15 1
    choices = MODE_LABELS_BY_KEY
16 1
    default = None
17
18 1
    group = (_('Sync - Lists (Beta)'), _('Watchlist'))
19 1
    label = _('Mode')
20 1
    description = Description(
21
        _("Syncing mode for watchlist items *(applies to both automatic and manual syncs)*."), [
22
            (_("Full"), _(
23
                "Synchronize watchlist items with your Trakt.tv profile"
24
            )),
25
            (_("Pull"), _(
26
                "Only pull watchlist items from your Trakt.tv profile"
27
            )),
28
            (_("Push"), _(
29
                "*Not implemented yet*"
30
            )),
31
            (_("Fast Pull"), _(
32
                "Only pull changes to watchlist items from your Trakt.tv profile"
33
            )),
34
            (_("Disabled"), _(
35
                "Completely disable syncing of watchlist items"
36
            ))
37
        ]
38
    )
39 1
    order = 320
40
41 1
    preference = 'sync_watchlist'
42
43 1
    def on_database_changed(self, value, account=None):
44
        if value not in MODE_IDS_BY_KEY:
45
            log.warn('Unknown value: %r', value)
46
            return
47
48
        # Map `value` to plex preference
49
        value = MODE_IDS_BY_KEY[value]
50
51
        # Update preference
52
        return self._update_preference(value, account)
53
54 1
    def on_plex_changed(self, value, account=None):
55
        if value not in MODE_KEYS_BY_LABEL:
56
            log.warn('Unknown value: %r', value)
57
            return
58
59
        # Map plex `value`
60
        value = MODE_KEYS_BY_LABEL[value]
61
62
        # Update database
63
        self.update(value, account, emit=False)
64
        return value
65
66
67 1
class SyncListsWatchlistPlaylistsOption(SimpleOption):
0 ignored issues
show
Bug introduced by
The method on_plex_changed which was declared abstract in the super-class Option
was not overridden.

Methods which raise NotImplementedError should be overridden in concrete child classes.

Loading history...
68 1
    key = 'sync.lists.watchlist.playlists'
69 1
    type = 'boolean'
70
71 1
    default = True
72
73 1
    group = (_('Sync - Lists (Beta)'), _('Watchlist'))
74 1
    label = _('Create playlist in plex')
75 1
    description = _(
76
        "Create playlist in Plex if it doesn't already exist."
77
    )
78 1
    order = 321
79
80
    # preference = 'sync_watched'
81
    #
82
    # def on_database_changed(self, value, account=None):
83
    #     if value not in MODE_IDS_BY_KEY:
84
    #         log.warn('Unknown value: %r', value)
85
    #         return
86
    #
87
    #     # Map `value` to plex preference
88
    #     value = MODE_IDS_BY_KEY[value]
89
    #
90
    #     # Update preference
91
    #     return self._update_preference(value, account)
92
    #
93
    # def on_plex_changed(self, value, account=None):
94
    #     if value not in MODE_KEYS_BY_LABEL:
95
    #         log.warn('Unknown value: %r', value)
96
    #         return
97
    #
98
    #     # Map plex `value`
99
    #     value = MODE_KEYS_BY_LABEL[value]
100
    #
101
    #     # Update database
102
    #     self.update(value, account, emit=False)
103
    #     return value
104