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 |
||
| 12 | class Give_Email_Setting_Field { |
||
| 13 | /** |
||
| 14 | * Get setting field. |
||
| 15 | * |
||
| 16 | * @since 2.0 |
||
| 17 | * @access public |
||
| 18 | * |
||
| 19 | * @param Give_Email_Notification $email |
||
| 20 | * @param int $form_id |
||
| 21 | * |
||
| 22 | * @return array |
||
| 23 | */ |
||
| 24 | public static function get_setting_fields( Give_Email_Notification $email, $form_id = null ) { |
||
| 49 | |||
| 50 | |||
| 51 | /** |
||
| 52 | * Check if email notification setting has section end or not. |
||
| 53 | * |
||
| 54 | * @since 2.0 |
||
| 55 | * @access private |
||
| 56 | * |
||
| 57 | * @param $setting |
||
| 58 | * |
||
| 59 | * @return bool |
||
| 60 | */ |
||
| 61 | public static function has_section_end( $setting ) { |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Check if email notification setting has section end or not. |
||
| 74 | * |
||
| 75 | * @since 2.0 |
||
| 76 | * @access private |
||
| 77 | * |
||
| 78 | * @param Give_Email_Notification $email |
||
| 79 | * @param int $form_id |
||
| 80 | * |
||
| 81 | * @return array |
||
| 82 | */ |
||
| 83 | public static function get_section_start( Give_Email_Notification $email, $form_id = null ) { |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Check if email notification setting has section end or not. |
||
| 96 | * |
||
| 97 | * @since 2.0 |
||
| 98 | * @access private |
||
| 99 | * |
||
| 100 | * @param array $setting |
||
| 101 | * @param Give_Email_Notification $email |
||
| 102 | * |
||
| 103 | * @return array |
||
| 104 | */ |
||
| 105 | public static function add_section_end( Give_Email_Notification $email, $setting ) { |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Get default setting field. |
||
| 119 | * |
||
| 120 | * @since 2.0 |
||
| 121 | * @access static |
||
| 122 | * |
||
| 123 | * @param Give_Email_Notification $email |
||
| 124 | * @param int $form_id |
||
| 125 | * |
||
| 126 | * @return array |
||
| 127 | */ |
||
| 128 | public static function get_default_setting_fields( Give_Email_Notification $email, $form_id = null ) { |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Get notification status setting field. |
||
| 155 | * |
||
| 156 | * @since 2.0 |
||
| 157 | * @access static |
||
| 158 | * |
||
| 159 | * @param Give_Email_Notification $email |
||
| 160 | * @param int $form_id |
||
| 161 | * |
||
| 162 | * @return array |
||
| 163 | */ |
||
| 164 | public static function get_notification_status_field( Give_Email_Notification $email, $form_id = null ) { |
||
| 195 | |||
| 196 | /** |
||
| 197 | * Get email subject setting field. |
||
| 198 | * |
||
| 199 | * @since 2.0 |
||
| 200 | * @access static |
||
| 201 | * |
||
| 202 | * @param Give_Email_Notification $email |
||
| 203 | * @param int $form_id |
||
| 204 | * |
||
| 205 | * @return array |
||
| 206 | */ |
||
| 207 | View Code Duplication | public static function get_email_subject_field( Give_Email_Notification $email, $form_id = null ) { |
|
| 216 | |||
| 217 | /** |
||
| 218 | * Get email header setting field. |
||
| 219 | * |
||
| 220 | * @since 2.1.3 |
||
| 221 | * |
||
| 222 | * @param Give_Email_Notification $email The email object. |
||
| 223 | * @param int $form_id The Form ID. |
||
| 224 | * |
||
| 225 | * @return array |
||
| 226 | */ |
||
| 227 | View Code Duplication | public static function get_email_header_field( Give_Email_Notification $email, $form_id = null ) { |
|
| 236 | |||
| 237 | /** |
||
| 238 | * Get email message setting field. |
||
| 239 | * |
||
| 240 | * @since 2.0 |
||
| 241 | * @access static |
||
| 242 | * |
||
| 243 | * @param Give_Email_Notification $email |
||
| 244 | * @param int $form_id |
||
| 245 | * |
||
| 246 | * @return array |
||
| 247 | */ |
||
| 248 | public static function get_email_message_field( Give_Email_Notification $email, $form_id = null ) { |
||
| 275 | |||
| 276 | /** |
||
| 277 | * Get email message setting field. |
||
| 278 | * |
||
| 279 | * @since 2.0 |
||
| 280 | * @access static |
||
| 281 | * |
||
| 282 | * @param Give_Email_Notification $email |
||
| 283 | * @param int $form_id |
||
| 284 | * |
||
| 285 | * @return array |
||
| 286 | */ |
||
| 287 | public static function get_email_content_type_field( Give_Email_Notification $email, $form_id = null ) { |
||
| 300 | |||
| 301 | |||
| 302 | /** |
||
| 303 | * Get recipient setting field. |
||
| 304 | * |
||
| 305 | * @since 2.0 |
||
| 306 | * @access public |
||
| 307 | * @todo check this field in form metabox setting after form api merge. |
||
| 308 | * |
||
| 309 | * @param Give_Email_Notification $email |
||
| 310 | * @param int $form_id |
||
| 311 | * @param bool $edit_recipient |
||
| 312 | * |
||
| 313 | * @return array |
||
| 314 | */ |
||
| 315 | public static function get_recipient_setting_field( Give_Email_Notification $email, $form_id = null, $edit_recipient = true ) { |
||
| 362 | |||
| 363 | /** |
||
| 364 | * Get preview setting field. |
||
| 365 | * |
||
| 366 | * @param Give_Email_Notification $email Email Type. |
||
| 367 | * @param int $form_id Form ID. |
||
| 368 | * |
||
| 369 | * @since 2.0 |
||
| 370 | * @access static |
||
| 371 | * |
||
| 372 | * @return array |
||
| 373 | */ |
||
| 374 | public static function get_preview_setting_field( Give_Email_Notification $email, $form_id = null ) { |
||
| 383 | |||
| 384 | |||
| 385 | /** |
||
| 386 | * Get form metabox setting field prefix. |
||
| 387 | * |
||
| 388 | * @since 2.0 |
||
| 389 | * @access static |
||
| 390 | * |
||
| 391 | * @param Give_Email_Notification $email |
||
| 392 | * @param int $form_id |
||
| 393 | * |
||
| 394 | * @return string |
||
| 395 | */ |
||
| 396 | public static function get_prefix( Give_Email_Notification $email, $form_id = null ) { |
||
| 405 | } |
||
| 406 | |||
| 408 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.