Conditions | 52 |
Total Lines | 65 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
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 data_filter() 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 | import hmac |
||
13 | def data_filter(trigger_id, **data): |
||
14 | """ |
||
15 | check if we want to track event for a given action |
||
16 | :param trigger_id: |
||
17 | :param data: |
||
18 | :return: |
||
19 | """ |
||
20 | taiga = Taiga.objects.get(trigger_id=trigger_id) |
||
21 | |||
22 | action = data.get('action') |
||
23 | type = data.get('type') |
||
24 | data = data.get('data') |
||
25 | |||
26 | if type == 'epic' and action == 'create' and taiga.notify_epic_create: |
||
27 | data['type_action'] = 'New Epic created' |
||
28 | elif type == 'epic' and action == 'change' and taiga.notify_epic_change: |
||
29 | data['type_action'] = 'Changed Epic' |
||
30 | elif type == 'epic' and action == 'delete' and taiga.notify_epic_delete: |
||
31 | data['type_action'] = 'Deleted Epic' |
||
32 | elif type == 'issue' and action == 'create' and \ |
||
33 | taiga.notify_issue_create: |
||
34 | data['type_action'] = 'New Issue created' |
||
35 | elif type == 'issue' and action == 'change' and \ |
||
36 | taiga.notify_issue_change: |
||
37 | data['type_action'] = 'Changed Issue' |
||
38 | elif type == 'issue' and action == 'delete' and \ |
||
39 | taiga.notify_issue_delete: |
||
40 | data['type_action'] = 'Deleted Issue' |
||
41 | elif type == 'userstory' and action == 'create' and \ |
||
42 | taiga.notify_userstory_create: |
||
43 | data['type_action'] = 'New Userstory created' |
||
44 | elif type == 'userstory' and action == 'change' and \ |
||
45 | taiga.notify_userstory_change: |
||
46 | data['type_action'] = 'Changed Userstory' |
||
47 | elif type == 'userstory' and action == 'delete' and \ |
||
48 | taiga.notify_userstory_delete: |
||
49 | data['type_action'] = 'Deleted Userstory' |
||
50 | elif type == 'task' and action == 'create' and \ |
||
51 | taiga.notify_task_create: |
||
52 | data['type_action'] = 'New Task created' |
||
53 | elif type == 'task' and action == 'change' and \ |
||
54 | taiga.notify_task_change: |
||
55 | data['type_action'] = 'Changed Task' |
||
56 | elif type == 'task' and action == 'delete' and \ |
||
57 | taiga.notify_task_delete: |
||
58 | data['type_action'] = 'Deleted Task' |
||
59 | elif type == 'wikipage' and action == 'create' and \ |
||
60 | taiga.notify_wikipage_create: |
||
61 | data['type_action'] = 'New Wikipage created' |
||
62 | elif type == 'wikipage' and action == 'change' and \ |
||
63 | taiga.notify_wikipage_change: |
||
64 | data['type_action'] = 'Changed Wikipage' |
||
65 | elif type == 'wikipage' and action == 'delete' and \ |
||
66 | taiga.notify_wikipage_delete: |
||
67 | data['type_action'] = 'Deleted Wikipage' |
||
68 | elif type == 'relateduserstory' and action == 'create' and \ |
||
69 | taiga.notify_relateduserstory_create: |
||
70 | data['type_action'] = 'New Related Userstory created' |
||
71 | elif type == 'relateduserstory' and action == 'delete' and \ |
||
72 | taiga.notify_relateduserstory_delete: |
||
73 | data['type_action'] = 'Deleted Related Userstory' |
||
74 | else: |
||
75 | data = [] |
||
76 | |||
77 | return data |
||
78 | |||
117 |