| Conditions | 11 |
| Paths | 35 |
| Total Lines | 68 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 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 |
||
| 27 | public function request_handler() { |
||
| 28 | if ( isset( $_POST['bd_action'] ) ) { |
||
| 29 | $bd_action = sanitize_text_field( $_POST['bd_action'] ); |
||
| 30 | $nonce_valid = false; |
||
| 31 | |||
| 32 | if ( 'delete_pages_' === substr( $bd_action, 0, strlen( 'delete_pages_' ) ) |
||
| 33 | && check_admin_referer( 'sm-bulk-delete-pages', 'sm-bulk-delete-pages-nonce' ) ) { |
||
| 34 | $nonce_valid = true; |
||
| 35 | } |
||
| 36 | |||
| 37 | if ( 'delete_posts_' === substr( $bd_action, 0, strlen( 'delete_posts_' ) ) |
||
| 38 | && check_admin_referer( 'sm-bulk-delete-posts', 'sm-bulk-delete-posts-nonce' ) ) { |
||
| 39 | $nonce_valid = true; |
||
| 40 | } |
||
| 41 | |||
| 42 | if ( 'delete_meta_' === substr( $bd_action, 0, strlen( 'delete_meta_' ) ) |
||
| 43 | && check_admin_referer( 'sm-bulk-delete-meta', 'sm-bulk-delete-meta-nonce' ) ) { |
||
| 44 | $nonce_valid = true; |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Perform nonce check. |
||
| 49 | * |
||
| 50 | * @since 5.5 |
||
| 51 | */ |
||
| 52 | if ( ! apply_filters( 'bd_action_nonce_check', $nonce_valid, $bd_action ) ) { |
||
| 53 | return; |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Before performing a bulk action. |
||
| 58 | * This hook is for doing actions just before performing any bulk operation |
||
| 59 | * |
||
| 60 | * @since 5.4 |
||
| 61 | */ |
||
| 62 | do_action( 'bd_pre_bulk_action', $bd_action ); |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Perform the bulk operation. |
||
| 66 | * This hook is for doing the bulk operation. Nonce check has already happened by this point. |
||
| 67 | * |
||
| 68 | * @since 5.4 |
||
| 69 | */ |
||
| 70 | do_action( 'bd_' . $bd_action, $_POST ); |
||
| 71 | } |
||
| 72 | |||
| 73 | if ( isset( $_GET['bd_action'] ) ) { |
||
| 74 | $bd_action = sanitize_text_field( $_GET['bd_action'] ); |
||
| 75 | $nonce_valid = false; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Perform nonce check. |
||
| 79 | * |
||
| 80 | * @since 5.5.4 |
||
| 81 | */ |
||
| 82 | if ( ! apply_filters( 'bd_get_action_nonce_check', $nonce_valid, $bd_action ) ) { |
||
| 83 | return; |
||
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Perform the bulk operation. |
||
| 88 | * This hook is for doing the bulk operation. Nonce check has already happened by this point. |
||
| 89 | * |
||
| 90 | * @since 5.5.4 |
||
| 91 | */ |
||
| 92 | do_action( 'bd_' . $bd_action, $_GET ); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 112 |