Conditions | 14 |
Total Lines | 56 |
Lines | 0 |
Ratio | 0 % |
Tests | 1 |
CRAP Score | 190.4058 |
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 Mode.get_enabled_data() 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.filters import Filters |
|
152 | 1 | def get_enabled_data(self): |
|
153 | config = self.configuration |
||
154 | |||
155 | # Determine accepted modes |
||
156 | modes = [SyncMode.Full] |
||
157 | |||
158 | if self.mode == SyncMode.Full: |
||
159 | modes.extend([ |
||
160 | SyncMode.FastPull, |
||
161 | SyncMode.Pull, |
||
162 | SyncMode.Push |
||
163 | ]) |
||
164 | elif self.mode == SyncMode.FastPull: |
||
165 | modes.extend([ |
||
166 | self.mode, |
||
167 | SyncMode.Pull |
||
168 | ]) |
||
169 | else: |
||
170 | modes.append(self.mode) |
||
171 | |||
172 | # Retrieve enabled data |
||
173 | result = [] |
||
174 | |||
175 | if config['sync.watched.mode'] in modes: |
||
176 | result.append(SyncData.Watched) |
||
177 | |||
178 | if config['sync.ratings.mode'] in modes: |
||
179 | result.append(SyncData.Ratings) |
||
180 | |||
181 | if config['sync.playback.mode'] in modes: |
||
182 | result.append(SyncData.Playback) |
||
183 | |||
184 | if config['sync.collection.mode'] in modes: |
||
185 | result.append(SyncData.Collection) |
||
186 | |||
187 | # Lists |
||
188 | if config['sync.lists.watchlist.mode'] in modes: |
||
189 | result.append(SyncData.Watchlist) |
||
190 | |||
191 | if config['sync.lists.liked.mode'] in modes: |
||
192 | result.append(SyncData.Liked) |
||
193 | |||
194 | if config['sync.lists.personal.mode'] in modes: |
||
195 | result.append(SyncData.Personal) |
||
196 | |||
197 | # Filter `result` to data provided by this mode |
||
198 | if self.data is None: |
||
199 | log.warn('No "data" property defined on %r', self) |
||
200 | return result |
||
201 | |||
202 | if self.data == SyncData.All: |
||
203 | return result |
||
204 | |||
205 | return [ |
||
206 | data for data in result |
||
207 | if data in self.data |
||
208 | ] |
||
248 |