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 |
||
24 | class Give_DB_Sequential_Ordering extends Give_DB { |
||
25 | |||
26 | /** |
||
27 | * Give_DB_Sequential_Ordering constructor. |
||
28 | * |
||
29 | * Set up the Give DB Donor class. |
||
30 | * |
||
31 | * @since 2.1.0 |
||
32 | * @access public |
||
33 | */ |
||
34 | View Code Duplication | public function __construct() { |
|
|
|||
35 | /* @var WPDB $wpdb */ |
||
36 | global $wpdb; |
||
37 | |||
38 | $this->table_name = $wpdb->prefix . 'give_sequential_ordering'; |
||
39 | $this->primary_key = 'id'; |
||
40 | $this->version = '1.0'; |
||
41 | |||
42 | // Install table. |
||
43 | $this->register_table(); |
||
44 | |||
45 | parent::__construct(); |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * Get columns and formats |
||
50 | * |
||
51 | * @since 2.1.0 |
||
52 | * @access public |
||
53 | * |
||
54 | * @return array Columns and formats. |
||
55 | */ |
||
56 | public function get_columns() { |
||
62 | |||
63 | /** |
||
64 | * Get default column values |
||
65 | * |
||
66 | * @since 2.1.0 |
||
67 | * @access public |
||
68 | * |
||
69 | * @return array Default column values. |
||
70 | */ |
||
71 | public function get_column_defaults() { |
||
77 | |||
78 | |||
79 | /** |
||
80 | * Create the table |
||
81 | * |
||
82 | * @since 2.1.0 |
||
83 | * @access public |
||
84 | * |
||
85 | * @return void |
||
86 | */ |
||
87 | public function create_table() { |
||
124 | |||
125 | |||
126 | /** |
||
127 | * Get id auto increment next value. |
||
128 | * |
||
129 | * @since 2.1.0 |
||
130 | * @return null|string |
||
131 | */ |
||
132 | public function get_id_auto_increment_val() { |
||
148 | } |
||
149 |
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.