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_Log_Meta extends Give_DB_Meta { |
||
| 25 | /** |
||
| 26 | * Meta supports. |
||
| 27 | * |
||
| 28 | * @since 2.0 |
||
| 29 | * @access protected |
||
| 30 | * @var array |
||
| 31 | */ |
||
| 32 | protected $supports = array( |
||
| 33 | 'add_post_metadata', |
||
| 34 | 'get_post_metadata', |
||
| 35 | 'update_post_metadata', |
||
| 36 | 'delete_post_metadata', |
||
| 37 | ); |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Post type |
||
| 41 | * |
||
| 42 | * @since 2.0 |
||
| 43 | * @access protected |
||
| 44 | * @var bool |
||
| 45 | */ |
||
| 46 | protected $post_type = 'give_log'; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Meta type |
||
| 50 | * |
||
| 51 | * @since 2.0 |
||
| 52 | * @access protected |
||
| 53 | * @var bool |
||
| 54 | */ |
||
| 55 | protected $meta_type = 'log'; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Give_DB_Log_Meta constructor. |
||
| 59 | * |
||
| 60 | * @access public |
||
| 61 | * @since 2.0 |
||
| 62 | */ |
||
| 63 | View Code Duplication | public function __construct() { |
|
| 75 | |||
| 76 | /** |
||
| 77 | * Get table columns and data types. |
||
| 78 | * |
||
| 79 | * @access public |
||
| 80 | * @since 2.0 |
||
| 81 | * |
||
| 82 | * @return array Columns and formats. |
||
| 83 | */ |
||
| 84 | public function get_columns() { |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Delete all log meta |
||
| 95 | * |
||
| 96 | * @since 2.0 |
||
| 97 | * @access public |
||
| 98 | * |
||
| 99 | * @param int $log_id |
||
| 100 | * |
||
| 101 | * @return bool |
||
| 102 | */ |
||
| 103 | View Code Duplication | public function delete_row( $log_id = 0 ) { |
|
| 120 | |||
| 121 | /** |
||
| 122 | * Create the table |
||
| 123 | * |
||
| 124 | * @access public |
||
| 125 | * @since 2.0 |
||
| 126 | * |
||
| 127 | * @return void |
||
| 128 | */ |
||
| 129 | public function create_table() { |
||
| 148 | |||
| 149 | |||
| 150 | /** |
||
| 151 | * Add support for hidden functions. |
||
| 152 | * |
||
| 153 | * @since 2.0 |
||
| 154 | * @access public |
||
| 155 | * |
||
| 156 | * @param $name |
||
| 157 | * @param $arguments |
||
| 158 | * |
||
| 159 | * @return mixed |
||
| 160 | */ |
||
| 161 | View Code Duplication | public function __call( $name, $arguments ) { |
|
| 204 | } |
||
| 205 |
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.