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