| Conditions | 10 |
| Paths | 60 |
| Total Lines | 68 |
| 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 |
||
| 87 | public function handle($request_data, $admin_base_url) |
||
| 88 | { |
||
| 89 | $deletion_job_code = isset($request_data['deletion_job_code']) ? sanitize_key($request_data['deletion_job_code']) : ''; |
||
| 90 | $models_and_ids_to_delete = $this->dao->getModelsAndIdsFromGroup($deletion_job_code); |
||
| 91 | $event_ids = isset($models_and_ids_to_delete['Event']) ? $models_and_ids_to_delete['Event'] : array(); |
||
| 92 | if (empty($event_ids) || !is_array($event_ids)) { |
||
| 93 | throw new EE_Error( |
||
| 94 | esc_html__('No Events were found to delete.', 'event_espresso') |
||
| 95 | ); |
||
| 96 | } |
||
| 97 | $datetime_ids = isset($models_and_ids_to_delete['Datetime']) ? $models_and_ids_to_delete['Datetime'] : array(); |
||
| 98 | if (!is_array($datetime_ids)) { |
||
| 99 | throw new UnexpectedEntityException($datetime_ids, 'array'); |
||
| 100 | } |
||
| 101 | $registration_ids = isset($models_and_ids_to_delete['Registration']) ? $models_and_ids_to_delete['Registration'] : array(); |
||
| 102 | if (!is_array($registration_ids)) { |
||
| 103 | throw new UnexpectedEntityException($registration_ids, 'array'); |
||
| 104 | } |
||
| 105 | $num_registrations_to_show = 10; |
||
| 106 | $reg_count = count($registration_ids); |
||
| 107 | if ($reg_count > $num_registrations_to_show) { |
||
| 108 | $registration_ids = array_slice($registration_ids, 0, $num_registrations_to_show); |
||
| 109 | } |
||
| 110 | $form = new ConfirmEventDeletionForm($event_ids); |
||
| 111 | $events = $this->event_model->get_all_deleted_and_undeleted( |
||
| 112 | [ |
||
| 113 | [ |
||
| 114 | 'EVT_ID' => ['IN', $event_ids] |
||
| 115 | ] |
||
| 116 | ] |
||
| 117 | ); |
||
| 118 | $datetimes = $this->datetime_model->get_all_deleted_and_undeleted( |
||
| 119 | [ |
||
| 120 | [ |
||
| 121 | 'DTT_ID' => ['IN', $datetime_ids] |
||
| 122 | ] |
||
| 123 | ] |
||
| 124 | ); |
||
| 125 | $registrations = $this->registration_model->get_all_deleted_and_undeleted( |
||
| 126 | [ |
||
| 127 | [ |
||
| 128 | 'REG_ID' => ['IN', $registration_ids] |
||
| 129 | ] |
||
| 130 | ] |
||
| 131 | ); |
||
| 132 | $confirm_deletion_args = [ |
||
| 133 | 'action' => 'confirm_deletion', |
||
| 134 | 'deletion_job_code' => $deletion_job_code |
||
| 135 | ]; |
||
| 136 | return [ |
||
| 137 | 'admin_page_content' => EEH_Template::display_template( |
||
| 138 | EVENTS_TEMPLATE_PATH . 'event_preview_deletion.template.php', |
||
| 139 | [ |
||
| 140 | 'form_url' => EE_Admin_Page::add_query_args_and_nonce( |
||
| 141 | $confirm_deletion_args, |
||
| 142 | $admin_base_url |
||
| 143 | ), |
||
| 144 | 'form' => $form, |
||
| 145 | 'events' => $events, |
||
| 146 | 'datetimes' => $datetimes, |
||
| 147 | 'registrations' => $registrations, |
||
| 148 | 'reg_count' => $reg_count, |
||
| 149 | 'num_registrations_to_show' => $num_registrations_to_show |
||
| 150 | ], |
||
| 151 | true |
||
| 152 | ) |
||
| 153 | ]; |
||
| 154 | } |
||
| 155 | } |
||
| 158 |