Conditions | 10 |
Total Lines | 71 |
Code Lines | 50 |
Lines | 0 |
Ratio | 0 % |
Tests | 3 |
CRAP Score | 88.6586 |
Changes | 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 byceps.blueprints.seating.views.manage_seats_in_area() 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 | """ |
||
84 | 1 | @blueprint.route('/areas/<slug>/manage_seats') |
|
85 | 1 | @login_required |
|
86 | 1 | @templated('seating/view_area') |
|
87 | def manage_seats_in_area(slug): |
||
88 | """Manage seats for assigned tickets in area.""" |
||
89 | _abort_if_seat_management_disabled() |
||
90 | |||
91 | area = seating_area_service.find_area_for_party_by_slug(g.party_id, slug) |
||
92 | if area is None: |
||
93 | abort(404) |
||
94 | |||
95 | seat_management_enabled = _is_seat_management_enabled() |
||
96 | |||
97 | seats = seat_service.get_seats_with_tickets_for_area(area.id) |
||
98 | |||
99 | ticket_code = request.args.get('ticket_code') |
||
100 | selected_ticket_id = request.args.get('ticket_id') |
||
101 | |||
102 | if _is_seating_admin(g.current_user) and ticket_code: |
||
103 | ticket_code = ticket_code.upper() |
||
104 | ticket = ticket_service.find_ticket_by_code(ticket_code) |
||
105 | if ticket: |
||
106 | tickets = ticket_service.find_tickets_for_seat_manager( |
||
107 | ticket.get_seat_manager().id, g.party_id |
||
108 | ) |
||
109 | selected_ticket_id = ticket.id |
||
110 | else: |
||
111 | flash_error(f'Ticket code "{ticket_code}" not found.') |
||
112 | tickets = [] |
||
113 | selected_ticket_id = None |
||
114 | |||
115 | elif _is_seating_admin(g.current_user) and selected_ticket_id: |
||
116 | ticket = ticket_service.find_ticket(selected_ticket_id) |
||
117 | if ticket: |
||
118 | tickets = ticket_service.find_tickets_for_seat_manager( |
||
119 | ticket.get_seat_manager().id, g.party_id |
||
120 | ) |
||
121 | selected_ticket_id = ticket.id |
||
122 | else: |
||
123 | flash_error(f'Ticket ID "{selected_ticket_id}" not found.') |
||
124 | tickets = [] |
||
125 | selected_ticket_id = None |
||
126 | |||
127 | elif seat_management_enabled: |
||
128 | tickets = ticket_service.find_tickets_for_seat_manager( |
||
129 | g.current_user.id, g.party_id |
||
130 | ) |
||
131 | selected_ticket_id = None |
||
132 | |||
133 | else: |
||
134 | tickets = [] |
||
135 | selected_ticket_id = None |
||
136 | |||
137 | users_by_id = service.get_users(seats, tickets) |
||
138 | |||
139 | seats = service.get_seats(seats, users_by_id) |
||
140 | |||
141 | if seat_management_enabled: |
||
142 | managed_tickets = list( |
||
143 | service.get_managed_tickets(tickets, users_by_id) |
||
144 | ) |
||
145 | else: |
||
146 | managed_tickets = [] |
||
147 | |||
148 | return { |
||
149 | 'area': area, |
||
150 | 'seat_management_enabled': seat_management_enabled, |
||
151 | 'seats': seats, |
||
152 | 'manage_mode': True, |
||
153 | 'managed_tickets': managed_tickets, |
||
154 | 'selected_ticket_id': selected_ticket_id, |
||
155 | } |
||
290 |