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 Jetpack_Simple_Payments_Widget extends WP_Widget { |
||
| 16 | /** |
||
| 17 | * Constructor. |
||
| 18 | */ |
||
| 19 | View Code Duplication | function __construct() { |
|
| 28 | |||
| 29 | /** |
||
| 30 | * Front-end display of widget. |
||
| 31 | * |
||
| 32 | * @see WP_Widget::widget() |
||
| 33 | * |
||
| 34 | * @param array $args Widget arguments. |
||
| 35 | * @param array $instance Saved values from database. |
||
| 36 | */ |
||
| 37 | function widget( $args, $instance ) { |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Sanitize widget form values as they are saved. |
||
| 69 | * |
||
| 70 | * @see WP_Widget::update() |
||
| 71 | * |
||
| 72 | * @param array $new_instance Values just sent to be saved. |
||
| 73 | * @param array $old_instance Previously saved values from database. |
||
| 74 | * |
||
| 75 | * @return array Updated safe values to be saved. |
||
| 76 | */ |
||
| 77 | function update( $new_instance, $old_instance ) { |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Back-end widget form. |
||
| 86 | * |
||
| 87 | * @see WP_Widget::form() |
||
| 88 | * |
||
| 89 | * @param array $instance Previously saved values from database. |
||
| 90 | */ |
||
| 91 | function form( $instance ) { |
||
| 100 | } |
||
| 101 | |||
| 108 |