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 | class FrmFieldNumber extends FrmFieldType { |
||
| 7 | |||
| 8 | /** |
||
| 9 | * @var string |
||
| 10 | * @since 3.0 |
||
| 11 | */ |
||
| 12 | protected $type = 'number'; |
||
| 13 | protected $display_type = 'text'; |
||
| 14 | |||
| 15 | protected function field_settings_for_type() { |
||
| 30 | |||
| 31 | protected function extra_field_opts() { |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @since 3.01.03 |
||
| 41 | */ |
||
| 42 | protected function add_extra_html_atts( $args, &$input_html ) { |
||
| 45 | |||
| 46 | public function validate( $args ) { |
||
| 74 | |||
| 75 | /** |
||
| 76 | * IE fallback for number fields |
||
| 77 | * Remove the comma when HTML5 isn't supported |
||
| 78 | * |
||
| 79 | * @since 3.0 |
||
| 80 | */ |
||
| 81 | private function remove_commas_from_number( &$args ) { |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Force the value to be numeric before it's saved in the DB |
||
| 90 | */ |
||
| 91 | public function set_value_before_save( $value ) { |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @since 4.0 |
||
| 101 | */ |
||
| 102 | public function sanitize_value( &$value ) { |
||
| 105 | } |
||
| 106 |
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.