| Conditions | 4 |
| Paths | 8 |
| Total Lines | 51 |
| 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 |
||
| 62 | public function handle($request_data, $admin_base_url) |
||
| 63 | { |
||
| 64 | $deletion_job_code = isset($request_data['deletion_job_code']) ? sanitize_key($request_data['deletion_job_code']) : ''; |
||
| 65 | $models_and_ids_to_delete = $this->dao->getModelsAndIdsFromGroup($deletion_job_code); |
||
| 66 | $form = new ConfirmEventDeletionForm($models_and_ids_to_delete['Event']); |
||
| 67 | // Initialize the form from the request, and check if its valid. |
||
| 68 | $form->receive_form_submission($request_data); |
||
| 69 | if ($form->is_valid()) { |
||
| 70 | // Redirect the user to the deletion batch job. |
||
| 71 | EEH_URL::safeRedirectAndExit( |
||
| 72 | EE_Admin_Page::add_query_args_and_nonce( |
||
| 73 | array( |
||
| 74 | 'page' => 'espresso_batch', |
||
| 75 | 'batch' => EED_Batch::batch_job, |
||
| 76 | 'deletion_job_code' => $deletion_job_code, |
||
| 77 | 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\ExecuteBatchDeletion'), |
||
| 78 | 'return_url' => urlencode( |
||
| 79 | add_query_arg( |
||
| 80 | [ |
||
| 81 | 'status' => 'trash' |
||
| 82 | ], |
||
| 83 | EVENTS_ADMIN_URL |
||
| 84 | ) |
||
| 85 | ) |
||
| 86 | ), |
||
| 87 | admin_url() |
||
| 88 | ) |
||
| 89 | ); |
||
| 90 | } |
||
| 91 | // Dont' use $form->submission_error_message() because it adds the form input's label in front |
||
| 92 | // of each validation error which ends up looking quite confusing. |
||
| 93 | $validation_errors = $form->get_validation_errors_accumulated(); |
||
| 94 | foreach ($validation_errors as $validation_error) { |
||
| 95 | EE_Error::add_error( |
||
| 96 | $validation_error->getMessage(), |
||
| 97 | __FILE__, |
||
| 98 | __FUNCTION__, |
||
| 99 | __LINE__ |
||
| 100 | ); |
||
| 101 | } |
||
| 102 | |||
| 103 | EEH_URL::safeRedirectAndExit( |
||
| 104 | EE_Admin_Page::add_query_args_and_nonce( |
||
| 105 | [ |
||
| 106 | 'action' => 'preview_deletion', |
||
| 107 | 'deletion_job_code' => $deletion_job_code |
||
| 108 | ], |
||
| 109 | $admin_base_url |
||
| 110 | ) |
||
| 111 | ); |
||
| 112 | } |
||
| 113 | } |
||
| 116 |