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 |
||
| 6 | View Code Duplication | class FrmFieldRadio extends FrmFieldType { |
|
|
|
|||
| 7 | |||
| 8 | /** |
||
| 9 | * @var string |
||
| 10 | * @since 3.0 |
||
| 11 | */ |
||
| 12 | protected $type = 'radio'; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var bool |
||
| 16 | * @since 3.0 |
||
| 17 | */ |
||
| 18 | protected $holds_email_values = true; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Does the html for this field label need to include "for"? |
||
| 22 | * |
||
| 23 | * @var bool |
||
| 24 | * @since 3.06.01 |
||
| 25 | */ |
||
| 26 | protected $has_for_label = false; |
||
| 27 | |||
| 28 | protected function input_html() { |
||
| 31 | |||
| 32 | protected function include_form_builder_file() { |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Get the type of field being displayed. |
||
| 38 | * |
||
| 39 | * @since 4.02.01 |
||
| 40 | * @return array |
||
| 41 | */ |
||
| 42 | public function displayed_field_type( $field ) { |
||
| 47 | |||
| 48 | protected function extra_field_opts() { |
||
| 55 | |||
| 56 | protected function new_field_settings() { |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @since 4.06 |
||
| 69 | */ |
||
| 70 | protected function show_priority_field_choices( $args = array() ) { |
||
| 73 | |||
| 74 | protected function include_front_form_file() { |
||
| 77 | |||
| 78 | protected function show_readonly_hidden() { |
||
| 81 | } |
||
| 82 |
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.