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 |
||
23 | class Give_Settings_Page { |
||
24 | |||
25 | /** |
||
26 | * Setting page id. |
||
27 | * |
||
28 | * @since 1.8 |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $id = ''; |
||
32 | |||
33 | /** |
||
34 | * Setting page label. |
||
35 | * |
||
36 | * @since 1.8 |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $label = ''; |
||
40 | |||
41 | |||
42 | /** |
||
43 | * Default tab. |
||
44 | * |
||
45 | * @since 1.8 |
||
46 | * @var string |
||
47 | */ |
||
48 | protected $default_tab = ''; |
||
49 | |||
50 | /** |
||
51 | * Current setting page. |
||
52 | * |
||
53 | * @since 1.8 |
||
54 | * @var string|null |
||
55 | */ |
||
56 | private $current_setting_page = null; |
||
57 | |||
58 | /** |
||
59 | * Flag to check if enable saving option for setting page or not |
||
60 | * |
||
61 | * @since 1.8.17 |
||
62 | * @var bool |
||
63 | */ |
||
64 | protected $enable_save = true; |
||
65 | |||
66 | /** |
||
67 | * Constructor. |
||
68 | */ |
||
69 | public function __construct() { |
||
94 | |||
95 | |||
96 | /** |
||
97 | * Get setting id |
||
98 | * |
||
99 | * @since 1.8.17 |
||
100 | * @access public |
||
101 | * @return string |
||
102 | */ |
||
103 | public function get_id() { |
||
106 | |||
107 | /** |
||
108 | * Default setting tab. |
||
109 | * |
||
110 | * @since 1.8 |
||
111 | * |
||
112 | * @param $setting_tab |
||
113 | * |
||
114 | * @return string |
||
115 | */ |
||
116 | function set_default_setting_tab( $setting_tab ) { |
||
119 | |||
120 | /** |
||
121 | * Add this page to settings. |
||
122 | * |
||
123 | * @since 1.8 |
||
124 | * |
||
125 | * @param array $pages Lst of pages. |
||
126 | * |
||
127 | * @return array |
||
128 | */ |
||
129 | public function add_settings_page( $pages ) { |
||
134 | |||
135 | /** |
||
136 | * Get settings array. |
||
137 | * |
||
138 | * @since 1.8 |
||
139 | * @return array |
||
140 | */ |
||
141 | public function get_settings() { |
||
154 | |||
155 | /** |
||
156 | * Get sections. |
||
157 | * |
||
158 | * @since 1.8 |
||
159 | * @return array |
||
160 | */ |
||
161 | public function get_sections() { |
||
164 | |||
165 | /** |
||
166 | * Output sections. |
||
167 | * |
||
168 | * @since 1.8 |
||
169 | * @return void |
||
170 | */ |
||
171 | public function output_sections() { |
||
206 | |||
207 | /** |
||
208 | * Output the settings. |
||
209 | * |
||
210 | * Note: if you want to overwrite this function then manage show/hide save button in your class. |
||
211 | * |
||
212 | * @since 1.8 |
||
213 | * @return void |
||
214 | */ |
||
215 | public function output() { |
||
224 | |||
225 | /** |
||
226 | * Save settings. |
||
227 | * |
||
228 | * @since 1.8 |
||
229 | * @return void |
||
230 | */ |
||
231 | public function save() { |
||
244 | |||
245 | /** |
||
246 | * Get heading labels |
||
247 | * |
||
248 | * @since 1.8.7 |
||
249 | * @access private |
||
250 | * |
||
251 | * @return array |
||
252 | */ |
||
253 | private function get_heading() { |
||
265 | |||
266 | /** |
||
267 | * Get heading html |
||
268 | * |
||
269 | * @since 1.8.7 |
||
270 | * @access private |
||
271 | * |
||
272 | * @return string |
||
273 | */ |
||
274 | public function get_heading_html() { |
||
280 | } |
||
281 | |||
283 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.