Conditions | 12 |
Total Lines | 70 |
Lines | 0 |
Ratio | 0 % |
Tests | 1 |
CRAP Score | 142.0881 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like Movies.run() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | 1 | from plugin.core.constants import GUID_SERVICES |
|
63 | 1 | @elapsed.clock |
|
64 | def run(self): |
||
65 | # Process movies |
||
66 | for mo_id, guid, p_item in self.p_movies: |
||
67 | # Increment one step |
||
68 | self.current.progress.group(Movies).step() |
||
69 | |||
70 | # Ensure `guid` is available |
||
71 | if not guid or guid.service not in GUID_SERVICES: |
||
72 | mark_unsupported(self.p_unsupported, mo_id, guid, p_item) |
||
73 | continue |
||
74 | |||
75 | key = (guid.service, guid.id) |
||
76 | |||
77 | # Try retrieve `pk` for `key` |
||
78 | pk = self.trakt.table('movies').get(key) |
||
79 | |||
80 | # Store in item map |
||
81 | self.current.map.add(p_item.get('library_section'), mo_id, [key, pk]) |
||
82 | |||
83 | if pk is None: |
||
84 | # No `pk` found |
||
85 | continue |
||
86 | |||
87 | # Iterate over changed data |
||
88 | for key, result in self.trakt.changes: |
||
89 | media, data = key[0:2] |
||
90 | |||
91 | if media != SyncMedia.Movies: |
||
92 | # Ignore changes that aren't for movies |
||
93 | continue |
||
94 | |||
95 | if data == SyncData.Watchlist: |
||
96 | # Ignore watchlist data |
||
97 | continue |
||
98 | |||
99 | if not self.is_data_enabled(data): |
||
100 | # Data type has been disabled |
||
101 | continue |
||
102 | |||
103 | data_name = Cache.Data.get(data) |
||
104 | |||
105 | if data_name not in result.changes: |
||
106 | # No changes for collection |
||
107 | continue |
||
108 | |||
109 | for action, items in result.changes[data_name].items(): |
||
110 | t_item = items.get(pk) |
||
111 | |||
112 | if t_item is None: |
||
113 | # No item found in changes |
||
114 | continue |
||
115 | |||
116 | self.execute_handlers( |
||
117 | SyncMedia.Movies, data, |
||
118 | action=action, |
||
119 | key=mo_id, |
||
120 | |||
121 | p_item=p_item, |
||
122 | t_item=t_item |
||
123 | ) |
||
124 | |||
125 | # Task checkpoint |
||
126 | self.checkpoint() |
||
127 | |||
128 | # Stop progress group |
||
129 | self.current.progress.group(Movies).stop() |
||
130 | |||
131 | # Log details |
||
132 | log_unsupported(log, 'Found %d unsupported movie(s)\n%s', self.p_unsupported) |
||
133 |
This check looks for calls to members that are non-existent. These calls will fail.
The member could have been renamed or removed.