| Conditions | 7 |
| Paths | 6 |
| Total Lines | 69 |
| Code Lines | 35 |
| Lines | 18 |
| Ratio | 26.09 % |
| 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 |
||
| 153 | public function delete( $slug ) { |
||
| 154 | |||
| 155 | $delete = new Delete; |
||
| 156 | |||
| 157 | // Make sure that the current user is logged in & has full permissions. |
||
| 158 | if ( ! $delete->user_can_delete() ) { |
||
| 159 | return; |
||
| 160 | } |
||
| 161 | |||
| 162 | // Check that $cptslg has a string. |
||
| 163 | if ( empty( $slug ) ) { |
||
| 164 | return; |
||
| 165 | } |
||
| 166 | |||
| 167 | // Query for our terms |
||
| 168 | $args = array( |
||
| 169 | 'hide_empty' => false, |
||
| 170 | 'meta_query' => array( |
||
| 171 | 'relation' => 'OR', |
||
| 172 | array( |
||
| 173 | 'key' => 'dummypress_test_data', |
||
| 174 | 'value' => '__test__', |
||
| 175 | 'compare' => '=' |
||
| 176 | ), |
||
| 177 | array( |
||
| 178 | 'key' => 'evans_test_content', |
||
| 179 | 'value' => '__test__', |
||
| 180 | 'compare' => '=' |
||
| 181 | ), |
||
| 182 | ) |
||
| 183 | ); |
||
| 184 | |||
| 185 | $terms = get_terms( $slug, $args ); |
||
| 186 | |||
| 187 | if ( ! empty( $terms ) ) { |
||
| 188 | |||
| 189 | $events = array(); |
||
| 190 | |||
| 191 | View Code Duplication | foreach ( $terms as $term ) { |
|
| 192 | |||
| 193 | // Double check our set user meta value |
||
| 194 | if ( '__test__' != get_term_meta( $term->term_id, 'dummypress_test_data', true ) && '__test__' != get_term_meta( $term->term_id, 'evans_test_content', true ) ) { |
||
| 195 | continue; |
||
| 196 | } |
||
| 197 | |||
| 198 | $events[] = array( |
||
| 199 | 'action' => 'deleted', |
||
| 200 | 'oid' => $term->term_id, |
||
| 201 | 'type' => $slug, |
||
| 202 | 'link' => '' |
||
| 203 | ); |
||
| 204 | |||
| 205 | // Delete our term |
||
| 206 | wp_delete_term( $term->term_id, $slug ); |
||
| 207 | |||
| 208 | } |
||
| 209 | |||
| 210 | $taxonomy = get_taxonomy( $slug ); |
||
| 211 | |||
| 212 | $events[] = array( |
||
| 213 | 'action' => 'general', |
||
| 214 | 'message' => __( 'Deleted', 'dummybot' ) . ' ' . $taxonomy->labels->name |
||
| 215 | ); |
||
| 216 | |||
| 217 | return $events; |
||
| 218 | |||
| 219 | } |
||
| 220 | |||
| 221 | } |
||
| 222 | |||
| 224 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.