| Conditions | 12 |
| Total Lines | 72 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 1 |
| CRAP Score | 142.4922 |
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.sync.core.constants import GUID_AGENTS |
|
| 57 | 1 | @elapsed.clock |
|
| 58 | def run(self): |
||
| 59 | # Process movies |
||
| 60 | for mo_id, guid, p_item in self.p_movies: |
||
| 61 | # Increment one step |
||
| 62 | self.current.progress.group(Movies).step() |
||
| 63 | |||
| 64 | # Ensure `guid` is available |
||
| 65 | if not guid or guid.agent not in GUID_AGENTS: |
||
| 66 | mark_unsupported(self.p_unsupported, mo_id, guid, p_item) |
||
| 67 | continue |
||
| 68 | |||
| 69 | key = (guid.agent, guid.sid) |
||
| 70 | |||
| 71 | log.debug('Processing movie: %s', key) |
||
| 72 | |||
| 73 | # Try retrieve `pk` for `key` |
||
| 74 | pk = self.trakt.table.get(key) |
||
| 75 | |||
| 76 | # Store in item map |
||
| 77 | self.current.map.add(p_item.get('library_section'), mo_id, [key, pk]) |
||
| 78 | |||
| 79 | if pk is None: |
||
| 80 | # No `pk` found |
||
| 81 | continue |
||
| 82 | |||
| 83 | # Iterate over changed data |
||
| 84 | for key, result in self.trakt.changes: |
||
| 85 | media, data = key[0:2] |
||
| 86 | |||
| 87 | if media != SyncMedia.Movies: |
||
| 88 | # Ignore changes that aren't for movies |
||
| 89 | continue |
||
| 90 | |||
| 91 | if data == SyncData.Watchlist: |
||
| 92 | # Ignore watchlist data |
||
| 93 | continue |
||
| 94 | |||
| 95 | if not self.is_data_enabled(data): |
||
| 96 | # Data type has been disabled |
||
| 97 | continue |
||
| 98 | |||
| 99 | data_name = Cache.Data.get(data) |
||
| 100 | |||
| 101 | if data_name not in result.changes: |
||
| 102 | # No changes for collection |
||
| 103 | continue |
||
| 104 | |||
| 105 | for action, items in result.changes[data_name].items(): |
||
| 106 | t_item = items.get(pk) |
||
| 107 | |||
| 108 | if t_item is None: |
||
| 109 | # No item found in changes |
||
| 110 | continue |
||
| 111 | |||
| 112 | self.execute_handlers( |
||
| 113 | SyncMedia.Movies, data, |
||
| 114 | action=action, |
||
| 115 | key=mo_id, |
||
| 116 | |||
| 117 | p_item=p_item, |
||
| 118 | t_item=t_item |
||
| 119 | ) |
||
| 120 | |||
| 121 | # Task checkpoint |
||
| 122 | self.checkpoint() |
||
| 123 | |||
| 124 | # Stop progress group |
||
| 125 | self.current.progress.group(Movies).stop() |
||
| 126 | |||
| 127 | # Log details |
||
| 128 | log_unsupported(log, 'Found %d unsupported movie(s)\n%s', self.p_unsupported) |
||
| 129 |
This check looks for calls to members that are non-existent. These calls will fail.
The member could have been renamed or removed.