| Conditions | 18 |
| Total Lines | 64 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 order_checklist_items() 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 | from skf.api.security import log, val_num, val_float |
||
| 52 | def order_checklist_items(checklist_items, get_checklist_items_lvl, lvl): |
||
| 53 | ordered_checklist_items = [] |
||
| 54 | for item in checklist_items.items: |
||
| 55 | numbers = item.checklistID.split('.') |
||
| 56 | category = int(numbers[0]) |
||
| 57 | category_requirement = int(numbers[1]) |
||
| 58 | if (len(ordered_checklist_items) == 0): |
||
| 59 | ordered_checklist_items.append(item) |
||
| 60 | else: |
||
| 61 | y = 0 |
||
| 62 | while y < len(ordered_checklist_items): |
||
| 63 | numbers_ordered = ordered_checklist_items[y].checklistID.split('.') |
||
| 64 | category_ordered = int(numbers_ordered[0]) |
||
| 65 | category_requirement_ordered = int(numbers_ordered[1]) |
||
| 66 | if (category < category_ordered): |
||
| 67 | ordered_checklist_items.insert(y, item) |
||
| 68 | break |
||
| 69 | else: |
||
| 70 | if (category == category_ordered): |
||
| 71 | if (category_requirement < category_requirement_ordered): |
||
| 72 | ordered_checklist_items.insert(y, item) |
||
| 73 | break |
||
| 74 | y = y + 1 |
||
| 75 | if (y == len(ordered_checklist_items)): |
||
| 76 | ordered_checklist_items.insert(y, item) |
||
| 77 | |||
| 78 | if (get_checklist_items_lvl): |
||
| 79 | if (not (lvl == 6)): |
||
| 80 | i = 0 |
||
| 81 | previousItemLevel = -1 |
||
| 82 | orderedWithEmpties = [] |
||
| 83 | for item in ordered_checklist_items: |
||
| 84 | if ((item.checklist_items.level == 0 and previousItemLevel == 0) or (item.checklist_items.content == "Resiliency Against Reverse Engineering Requirements" and not (lvl == 6))): |
||
| 85 | if (item.checklist_items.content == "Resiliency Against Reverse Engineering Requirements"): |
||
| 86 | orderedWithEmpties.append(item) |
||
| 87 | previousItemLevel = item.checklist_items.level |
||
| 88 | checklist_empty = checklists("0.0", "Requirements of Reverse Engineering can be added to form a level " + str(lvl-3) + "+R.", -1, 0) |
||
| 89 | checklists_kb_empty = checklists_kb("0.0", checklist_empty, 0, None) |
||
| 90 | orderedWithEmpties.append(checklists_kb_empty) |
||
| 91 | else: |
||
| 92 | checklist_empty = checklists("0.0", "No items for this category in this checklist level", -1, 0) |
||
| 93 | checklists_kb_empty = checklists_kb("0.0", checklist_empty, 0, None) |
||
| 94 | orderedWithEmpties.append(checklists_kb_empty) |
||
| 95 | orderedWithEmpties.append(item) |
||
| 96 | previousItemLevel = item.checklist_items.level |
||
| 97 | else: |
||
| 98 | orderedWithEmpties.append(item) |
||
| 99 | previousItemLevel = item.checklist_items.level |
||
| 100 | i = i + 1; |
||
| 101 | checklist_items.items = orderedWithEmpties |
||
| 102 | else: |
||
| 103 | orderedWithR6 = [] |
||
| 104 | checklist_empty = checklists("0.0", "Using Requirements of Reverse Engineering you can form the levels L1+R or L2+R.", -1, 0) |
||
| 105 | checklists_kb_empty = checklists_kb("0.0", checklist_empty, 0, None) |
||
| 106 | orderedWithR6.append(checklists_kb_empty) |
||
| 107 | for item in ordered_checklist_items: |
||
| 108 | if (item.checklist_items.level == 'R'): |
||
| 109 | checklist_modified = checklists(item.checklistID, item.checklist_items.content, 6, item.checklist_items.kbID) |
||
| 110 | modifiedItem = checklists_kb(item.checklistID, checklist_modified, item.kbID, item.kb_items) |
||
| 111 | orderedWithR6.append(modifiedItem) |
||
| 112 | else: |
||
| 113 | orderedWithR6.append(item) |
||
| 114 | checklist_items.items = orderedWithR6 |
||
| 115 | return checklist_items |
||
| 116 |