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_Earnings_Report { |
||
| 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 | * Constructor. |
||
| 43 | */ |
||
| 44 | public function __construct() { |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Add this page to settings. |
||
| 61 | * |
||
| 62 | * @since 1.8 |
||
| 63 | * @param array $pages Lst of pages. |
||
| 64 | * @return array |
||
| 65 | */ |
||
| 66 | public function add_settings_page( $pages ) { |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Get settings array. |
||
| 74 | * |
||
| 75 | * @since 1.8 |
||
| 76 | * @return array |
||
| 77 | */ |
||
| 78 | public function get_settings() { |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Output the settings. |
||
| 115 | * |
||
| 116 | * @since 1.8 |
||
| 117 | * @return void |
||
| 118 | */ |
||
| 119 | public function output() { |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Render earning field |
||
| 127 | * |
||
| 128 | * @since 1.8 |
||
| 129 | * @access public |
||
| 130 | * |
||
| 131 | * @param $field |
||
| 132 | * @param $option_value |
||
| 133 | */ |
||
| 134 | public function render_report_earnings_field( $field, $option_value ) { |
||
| 137 | } |
||
| 138 | |||
| 142 |
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.