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_Form_Meta extends Give_DB_Meta { |
||
25 | /** |
||
26 | * Post type |
||
27 | * |
||
28 | * @since 2.0 |
||
29 | * @access protected |
||
30 | * @var bool |
||
31 | */ |
||
32 | protected $post_type = 'give_forms'; |
||
33 | |||
34 | /** |
||
35 | * Meta type |
||
36 | * |
||
37 | * @since 2.0 |
||
38 | * @access protected |
||
39 | * @var bool |
||
40 | */ |
||
41 | protected $meta_type = 'form'; |
||
42 | |||
43 | /** |
||
44 | * Give_DB_Form_Meta constructor. |
||
45 | * |
||
46 | * @access public |
||
47 | * @since 2.0 |
||
48 | */ |
||
49 | View Code Duplication | 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 | * check if custom meta table enabled or not. |
||
81 | * |
||
82 | * @since 2.0 |
||
83 | * @access protected |
||
84 | * @return bool |
||
85 | */ |
||
86 | protected function is_custom_meta_table_active() { |
||
89 | } |
||
90 |
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.