Conditions | 7 |
Total Lines | 57 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 56 |
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:
1 | 1 | from plugin.sync.core.constants import GUID_AGENTS |
|
124 | def process_missing_movies(self): |
||
125 | """Trigger actions for movies that are in trakt, but was unable to be found in plex""" |
||
126 | |||
127 | if self.current.kwargs.get('section'): |
||
128 | # Collection cleaning disabled for individual syncs |
||
129 | return |
||
130 | |||
131 | # Increment progress steps |
||
132 | self.current.progress.group(Movies, 'missing:movies').add(len(self.p_pending)) |
||
133 | |||
134 | # Iterate over movies |
||
135 | for pk in list(self.p_pending): |
||
136 | # Increment one step |
||
137 | self.current.progress.group(Movies, 'missing:movies').step() |
||
138 | |||
139 | # Iterate over data handlers |
||
140 | triggered = False |
||
141 | |||
142 | for data in self.get_data(SyncMedia.Movies): |
||
143 | if data not in [SyncData.Collection]: |
||
144 | continue |
||
145 | |||
146 | # Retrieve movie |
||
147 | t_movie = self.trakt[(SyncMedia.Movies, data)].get(pk) |
||
148 | |||
149 | if not t_movie: |
||
150 | continue |
||
151 | |||
152 | log.debug('Found movie missing from plex: %r [data: %r]', pk, SyncData.title(data)) |
||
153 | |||
154 | # Trigger handler |
||
155 | self.execute_handlers( |
||
156 | SyncMedia.Movies, data, |
||
157 | |||
158 | key=None, |
||
159 | |||
160 | guid=Guid(*pk), |
||
161 | p_item=None, |
||
162 | |||
163 | t_item=t_movie |
||
164 | ) |
||
165 | |||
166 | # Mark triggered |
||
167 | triggered = True |
||
168 | |||
169 | # Check if action was triggered |
||
170 | if not triggered: |
||
171 | continue |
||
172 | |||
173 | # Remove movie from `pending` set |
||
174 | self.p_pending.remove(pk) |
||
175 | |||
176 | # Stop progress group |
||
177 | self.current.progress.group(Movies, 'missing:movies').stop() |
||
178 | |||
179 | # Report pending movies (no actions triggered) |
||
180 | self.log_pending('Unable to process %d movie(s)\n%s', self.p_pending) |
||
181 |
This check looks for calls to members that are non-existent. These calls will fail.
The member could have been renamed or removed.