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 | |||
| 34 | /** |
||
| 35 | * Meta type |
||
| 36 | * |
||
| 37 | * @since 2.0 |
||
| 38 | * @access protected |
||
| 39 | * @var bool |
||
| 40 | */ |
||
| 41 | protected $meta_type = 'log'; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Give_DB_Log_Meta constructor. |
||
| 45 | * |
||
| 46 | * @access public |
||
| 47 | * @since 2.0 |
||
| 48 | */ |
||
| 49 | public function __construct() { |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Get table columns and data types. |
||
| 64 | * |
||
| 65 | * @access public |
||
| 66 | * @since 2.0 |
||
| 67 | * |
||
| 68 | * @return array Columns and formats. |
||
| 69 | */ |
||
| 70 | public function get_columns() { |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Delete all log meta |
||
| 81 | * |
||
| 82 | * @since 2.0 |
||
| 83 | * @access public |
||
| 84 | * |
||
| 85 | * @param int $log_id |
||
| 86 | * |
||
| 87 | * @return bool |
||
| 88 | */ |
||
| 89 | View Code Duplication | public function delete_row( $log_id = 0 ) { |
|
| 106 | |||
| 107 | /** |
||
| 108 | * Create the table |
||
| 109 | * |
||
| 110 | * @access public |
||
| 111 | * @since 2.0 |
||
| 112 | * |
||
| 113 | * @return void |
||
| 114 | */ |
||
| 115 | public function create_table() { |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Check if current id is valid |
||
| 137 | * |
||
| 138 | * @since 2.0 |
||
| 139 | * @access protected |
||
| 140 | * |
||
| 141 | * @param $ID |
||
| 142 | * |
||
| 143 | * @return bool |
||
| 144 | */ |
||
| 145 | protected function is_valid_post_type( $ID ) { |
||
| 148 | } |
||
| 149 |