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 FrmFieldUrl extends FrmFieldType { |
||
| 7 | |||
| 8 | /** |
||
| 9 | * @var string |
||
| 10 | * @since 3.0 |
||
| 11 | */ |
||
| 12 | protected $type = 'url'; |
||
| 13 | protected $display_type = 'text'; |
||
| 14 | |||
| 15 | View Code Duplication | protected function field_settings_for_type() { |
|
| 23 | |||
| 24 | /** |
||
| 25 | * @return array |
||
| 26 | */ |
||
| 27 | protected function extra_field_opts() { |
||
| 32 | |||
| 33 | protected function get_field_name() { |
||
| 36 | |||
| 37 | protected function fill_default_atts( &$atts ) { |
||
| 48 | |||
| 49 | public function validate( $args ) { |
||
| 65 | |||
| 66 | protected function prepare_display_value( $value, $atts ) { |
||
| 83 | } |
||
| 84 |
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.