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