Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
15 | class acf_admin_update { |
||
16 | |||
17 | /* |
||
18 | * __construct |
||
19 | * |
||
20 | * A good place to add actions / filters |
||
21 | * |
||
22 | * @type function |
||
23 | * @date 11/08/13 |
||
24 | * |
||
25 | * @param N/A |
||
26 | * @return N/A |
||
27 | */ |
||
|
|||
28 | |||
29 | function __construct() { |
||
40 | |||
41 | |||
42 | /* |
||
43 | * network_admin_menu |
||
44 | * |
||
45 | * This function will chck for available updates and add actions if needed |
||
46 | * |
||
47 | * @type function |
||
48 | * @date 2/04/2015 |
||
49 | * @since 5.1.5 |
||
50 | * |
||
51 | * @param n/a |
||
52 | * @return n/a |
||
53 | */ |
||
54 | |||
55 | function network_admin_menu() { |
||
116 | |||
117 | |||
118 | /* |
||
119 | * network_admin_notices |
||
120 | * |
||
121 | * This function will render the update notice |
||
122 | * |
||
123 | * @type function |
||
124 | * @date 2/04/2015 |
||
125 | * @since 5.1.5 |
||
126 | * |
||
127 | * @param n/a |
||
128 | * @return n/a |
||
129 | */ |
||
130 | |||
131 | View Code Duplication | function network_admin_notices() { |
|
153 | |||
154 | |||
155 | /* |
||
156 | * network_html |
||
157 | * |
||
158 | * This function will render the HTML for the network upgrade page |
||
159 | * |
||
160 | * @type function |
||
161 | * @date 19/02/2014 |
||
162 | * @since 5.0.0 |
||
163 | * |
||
164 | * @param n/a |
||
165 | * @return n/a |
||
166 | */ |
||
167 | |||
168 | function network_html() { |
||
233 | |||
234 | |||
235 | /* |
||
236 | * admin_menu |
||
237 | * |
||
238 | * This function will chck for available updates and add actions if needed |
||
239 | * |
||
240 | * @type function |
||
241 | * @date 19/02/2014 |
||
242 | * @since 5.0.0 |
||
243 | * |
||
244 | * @param n/a |
||
245 | * @return n/a |
||
246 | */ |
||
247 | |||
248 | function admin_menu() { |
||
301 | |||
302 | |||
303 | /* |
||
304 | * admin_notices |
||
305 | * |
||
306 | * This function will render any admin notices |
||
307 | * |
||
308 | * @type function |
||
309 | * @date 17/10/13 |
||
310 | * @since 5.0.0 |
||
311 | * |
||
312 | * @param n/a |
||
313 | * @return n/a |
||
314 | */ |
||
315 | |||
316 | View Code Duplication | function admin_notices() { |
|
337 | |||
338 | |||
339 | /* |
||
340 | * html |
||
341 | * |
||
342 | * description |
||
343 | * |
||
344 | * @type function |
||
345 | * @date 19/02/2014 |
||
346 | * @since 5.0.0 |
||
347 | * |
||
348 | * @param $post_id (int) |
||
349 | * @return $post_id (int) |
||
350 | */ |
||
351 | |||
352 | function html() { |
||
369 | |||
370 | |||
371 | /* |
||
372 | * ajax_upgrade |
||
373 | * |
||
374 | * description |
||
375 | * |
||
376 | * @type function |
||
377 | * @date 24/10/13 |
||
378 | * @since 5.0.0 |
||
379 | * |
||
380 | * @param $post_id (int) |
||
381 | * @return $post_id (int) |
||
382 | */ |
||
383 | |||
384 | function ajax_upgrade() { |
||
477 | |||
478 | |||
479 | /* |
||
480 | * inject_downgrade |
||
481 | * |
||
482 | * description |
||
483 | * |
||
484 | * @type function |
||
485 | * @date 16/01/2014 |
||
486 | * @since 5.0.0 |
||
487 | * |
||
488 | * @param $post_id (int) |
||
489 | * @return $post_id (int) |
||
490 | */ |
||
491 | |||
492 | /* |
||
493 | function inject_downgrade( $transient ) { |
||
494 | |||
495 | // bail early if no plugins are being checked |
||
496 | if( empty($transient->checked) ) { |
||
497 | |||
498 | return $transient; |
||
499 | |||
500 | } |
||
501 | |||
502 | |||
503 | // bail early if no nonce |
||
504 | if( empty($_GET['_acfrollback']) ) { |
||
505 | |||
506 | return $transient; |
||
507 | |||
508 | } |
||
509 | |||
510 | |||
511 | // vars |
||
512 | $rollback = get_option('acf_version'); |
||
513 | |||
514 | |||
515 | // bail early if nonce is not correct |
||
516 | if( !wp_verify_nonce( $_GET['_acfrollback'], 'rollback-acf_' . $rollback ) ) { |
||
517 | |||
518 | return $transient; |
||
519 | |||
520 | } |
||
521 | |||
522 | |||
523 | // create new object for update |
||
524 | $obj = new stdClass(); |
||
525 | $obj->slug = $_GET['plugin']; |
||
526 | $obj->new_version = $rollback; |
||
527 | $obj->url = 'https://wordpress.org/plugins/advanced-custom-fields'; |
||
528 | $obj->package = 'http://downloads.wordpress.org/plugin/advanced-custom-fields.' . $rollback . '.zip';; |
||
529 | |||
530 | |||
531 | // add to transient |
||
532 | $transient->response[ $_GET['plugin'] ] = $obj; |
||
533 | |||
534 | |||
535 | // return |
||
536 | return $transient; |
||
537 | } |
||
538 | */ |
||
539 | |||
540 | } |
||
541 | |||
548 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.