| Conditions | 10 |
| Paths | 21 |
| Total Lines | 43 |
| 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 |
||
| 67 | public function find_using_request_action( $allowed_actions ) { |
||
| 68 | // phpcs:disable WordPress.Security.NonceVerification.Recommended |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Note: we're not actually checking the nonce here because it's too early |
||
| 72 | * in the execution. The pluggable functions are not yet loaded to give |
||
| 73 | * plugins a chance to plug their versions. Therefore we're doing the bare |
||
| 74 | * minimum: checking whether the nonce exists and it's in the right place. |
||
| 75 | * The request will fail later if the nonce doesn't pass the check. |
||
| 76 | */ |
||
| 77 | if ( empty( $_REQUEST['_wpnonce'] ) ) { |
||
| 78 | return array(); |
||
| 79 | } |
||
| 80 | |||
| 81 | $action = isset( $_REQUEST['action'] ) ? wp_unslash( $_REQUEST['action'] ) : false; |
||
| 82 | if ( ! in_array( $action, $allowed_actions, true ) ) { |
||
| 83 | return array(); |
||
| 84 | } |
||
| 85 | |||
| 86 | $plugin_slugs = array(); |
||
| 87 | switch ( $action ) { |
||
| 88 | case 'activate': |
||
| 89 | case 'deactivate': |
||
| 90 | if ( empty( $_REQUEST['plugin'] ) ) { |
||
| 91 | break; |
||
| 92 | } |
||
| 93 | |||
| 94 | $plugin_slugs[] = wp_unslash( $_REQUEST['plugin'] ); |
||
| 95 | break; |
||
| 96 | |||
| 97 | case 'activate-selected': |
||
| 98 | case 'deactivate-selected': |
||
| 99 | if ( empty( $_REQUEST['checked'] ) ) { |
||
| 100 | break; |
||
| 101 | } |
||
| 102 | |||
| 103 | $plugin_slugs = wp_unslash( $_REQUEST['checked'] ); |
||
| 104 | break; |
||
| 105 | } |
||
| 106 | |||
| 107 | // phpcs:enable WordPress.Security.NonceVerification.Recommended |
||
| 108 | return $this->convert_plugins_to_paths( $plugin_slugs ); |
||
|
|
|||
| 109 | } |
||
| 110 | |||
| 140 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: