| Conditions | 10 |
| Paths | 60 |
| Total Lines | 72 |
| Lines | 0 |
| Ratio | 0 % |
| 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:
| 1 | <?php |
||
| 67 | public function handle(Events_Admin_Page $admin_page) |
||
| 68 | { |
||
| 69 | $request_data = $admin_page->get_request_data(); |
||
| 70 | $deletion_job_code = isset($request_data['deletion_job_code']) ? sanitize_key($request_data['deletion_job_code']) : ''; |
||
| 71 | $models_and_ids_to_delete = $this->dao->getModelsAndIdsFromGroup($deletion_job_code); |
||
| 72 | $event_ids = isset($models_and_ids_to_delete['Event']) ? $models_and_ids_to_delete['Event'] : array(); |
||
| 73 | if (empty($event_ids) || !is_array($event_ids)) { |
||
| 74 | throw new EE_Error( |
||
| 75 | esc_html__('No Events were found to delete.', 'event_espresso') |
||
| 76 | ); |
||
| 77 | } |
||
| 78 | $datetime_ids = isset($models_and_ids_to_delete['Datetime']) ? $models_and_ids_to_delete['Datetime'] : array(); |
||
| 79 | if (!is_array($datetime_ids)) { |
||
| 80 | throw new UnexpectedEntityException($datetime_ids, 'array'); |
||
| 81 | } |
||
| 82 | $registration_ids = isset($models_and_ids_to_delete['Registration']) ? $models_and_ids_to_delete['Registration'] : array(); |
||
| 83 | if (!is_array($registration_ids)) { |
||
| 84 | throw new UnexpectedEntityException($registration_ids, 'array'); |
||
| 85 | } |
||
| 86 | $num_registrations_to_show = 10; |
||
| 87 | $reg_count = count($registration_ids); |
||
| 88 | if ($reg_count > $num_registrations_to_show) { |
||
| 89 | $registration_ids = array_slice($registration_ids, 0, $num_registrations_to_show); |
||
| 90 | } |
||
| 91 | $form = new ConfirmEventDeletionForm($event_ids); |
||
| 92 | $events = $this->event_model->get_all_deleted_and_undeleted( |
||
| 93 | [ |
||
| 94 | [ |
||
| 95 | 'EVT_ID' => ['IN', $event_ids] |
||
| 96 | ] |
||
| 97 | ] |
||
| 98 | ); |
||
| 99 | $datetimes = $this->datetime_model->get_all_deleted_and_undeleted( |
||
| 100 | [ |
||
| 101 | [ |
||
| 102 | 'DTT_ID' => ['IN', $datetime_ids] |
||
| 103 | ] |
||
| 104 | ] |
||
| 105 | ); |
||
| 106 | $registrations = $this->registration_model->get_all_deleted_and_undeleted( |
||
| 107 | [ |
||
| 108 | [ |
||
| 109 | 'REG_ID' => ['IN', $registration_ids] |
||
| 110 | ] |
||
| 111 | ] |
||
| 112 | ); |
||
| 113 | $confirm_deletion_args = [ |
||
| 114 | 'action' => 'confirm_deletion', |
||
| 115 | 'deletion_job_code' => $deletion_job_code |
||
| 116 | ]; |
||
| 117 | $admin_page->set_template_args( |
||
| 118 | [ |
||
| 119 | 'admin_page_content' => EEH_Template::display_template( |
||
| 120 | EVENTS_TEMPLATE_PATH . 'event_preview_deletion.template.php', |
||
| 121 | [ |
||
| 122 | 'form_url' => EE_Admin_Page::add_query_args_and_nonce( |
||
| 123 | $confirm_deletion_args, |
||
| 124 | $admin_page->admin_base_url() |
||
| 125 | ), |
||
| 126 | 'form' => $form, |
||
| 127 | 'events' => $events, |
||
| 128 | 'datetimes' => $datetimes, |
||
| 129 | 'registrations' => $registrations, |
||
| 130 | 'reg_count' => $reg_count, |
||
| 131 | 'num_registrations_to_show' => $num_registrations_to_show |
||
| 132 | ], |
||
| 133 | true |
||
| 134 | ) |
||
| 135 | ] |
||
| 136 | ); |
||
| 137 | $admin_page->display_admin_page_with_no_sidebar(); |
||
| 138 | } |
||
| 139 | } |
||
| 142 |