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 |
||
69 | public function find_using_request_action( $allowed_actions ) { |
||
70 | // phpcs:disable WordPress.Security.NonceVerification.Recommended |
||
71 | |||
72 | /** |
||
73 | * Note: we're not actually checking the nonce here because it's too early |
||
74 | * in the execution. The pluggable functions are not yet loaded to give |
||
75 | * plugins a chance to plug their versions. Therefore we're doing the bare |
||
76 | * minimum: checking whether the nonce exists and it's in the right place. |
||
77 | * The request will fail later if the nonce doesn't pass the check. |
||
78 | */ |
||
79 | if ( empty( $_REQUEST['_wpnonce'] ) ) { |
||
80 | return array(); |
||
81 | } |
||
82 | |||
83 | $action = isset( $_REQUEST['action'] ) ? wp_unslash( $_REQUEST['action'] ) : false; |
||
84 | if ( ! in_array( $action, $allowed_actions, true ) ) { |
||
85 | return array(); |
||
86 | } |
||
87 | |||
88 | $plugin_slugs = array(); |
||
89 | switch ( $action ) { |
||
90 | case 'activate': |
||
91 | case 'deactivate': |
||
92 | if ( empty( $_REQUEST['plugin'] ) ) { |
||
93 | break; |
||
94 | } |
||
95 | |||
96 | $plugin_slugs[] = wp_unslash( $_REQUEST['plugin'] ); |
||
97 | break; |
||
98 | |||
99 | case 'activate-selected': |
||
100 | case 'deactivate-selected': |
||
101 | if ( empty( $_REQUEST['checked'] ) ) { |
||
102 | break; |
||
103 | } |
||
104 | |||
105 | $plugin_slugs = wp_unslash( $_REQUEST['checked'] ); |
||
106 | break; |
||
107 | } |
||
108 | |||
109 | // phpcs:enable WordPress.Security.NonceVerification.Recommended |
||
110 | return $this->convert_plugins_to_paths( $plugin_slugs ); |
||
|
|||
111 | } |
||
112 | |||
146 |
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: