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