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 |
||
16 | class WC_Widget_Recently_Viewed extends WC_Widget { |
||
17 | |||
18 | /** |
||
19 | * Constructor. |
||
20 | */ |
||
21 | public function __construct() { |
||
22 | $this->widget_cssclass = 'woocommerce widget_recently_viewed_products'; |
||
23 | $this->widget_description = __( 'Display a list of recently viewed products.', 'woocommerce' ); |
||
24 | $this->widget_id = 'woocommerce_recently_viewed_products'; |
||
25 | $this->widget_name = __( 'WooCommerce Recently Viewed', 'woocommerce' ); |
||
26 | $this->settings = array( |
||
27 | 'title' => array( |
||
28 | 'type' => 'text', |
||
29 | 'std' => __( 'Recently Viewed Products', 'woocommerce' ), |
||
30 | 'label' => __( 'Title', 'woocommerce' ) |
||
31 | ), |
||
32 | 'number' => array( |
||
33 | 'type' => 'number', |
||
34 | 'step' => 1, |
||
35 | 'min' => 1, |
||
36 | 'max' => '', |
||
37 | 'std' => 10, |
||
38 | 'label' => __( 'Number of products to show', 'woocommerce' ) |
||
39 | ) |
||
40 | ); |
||
41 | |||
42 | parent::__construct(); |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * Output widget. |
||
47 | * |
||
48 | * @see WP_Widget |
||
49 | * |
||
50 | * @param array $args |
||
51 | * @param array $instance |
||
52 | */ |
||
53 | public function widget( $args, $instance ) { |
||
96 | } |
||
97 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.