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 |
||
| 17 | class Jetpack_MailChimp_Subscriber_Popup_Widget extends WP_Widget { |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Constructor |
||
| 21 | */ |
||
| 22 | View Code Duplication | function __construct() { |
|
| 34 | |||
| 35 | /** |
||
| 36 | * Outputs the HTML for this widget. |
||
| 37 | * |
||
| 38 | * @param array $args An array of standard parameters for widgets in this theme |
||
| 39 | * @param array $instance An array of settings for this widget instance |
||
| 40 | * |
||
| 41 | * @return void Echoes it's output |
||
| 42 | **/ |
||
| 43 | function widget( $args, $instance ) { |
||
| 60 | |||
| 61 | |||
| 62 | /** |
||
| 63 | * Deals with the settings when they are saved by the admin. |
||
| 64 | * |
||
| 65 | * @param array $new_instance New configuration values |
||
| 66 | * @param array $old_instance Old configuration values |
||
| 67 | * |
||
| 68 | * @return array |
||
| 69 | */ |
||
| 70 | function update( $new_instance, $old_instance ) { |
||
| 76 | |||
| 77 | |||
| 78 | /** |
||
| 79 | * Displays the form for this widget on the Widgets page of the WP Admin area. |
||
| 80 | * |
||
| 81 | * @param array $instance Instance configuration. |
||
| 82 | * |
||
| 83 | * @return void |
||
| 84 | */ |
||
| 85 | function form( $instance ) { |
||
| 98 | |||
| 99 | } |
||
| 100 | |||
| 102 |