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_Settings_Data extends Give_Settings_Page { |
||
24 | |||
25 | /** |
||
26 | * Flag to check if enable saving option for setting page or not |
||
27 | * |
||
28 | * @since 1.8.17 |
||
29 | * @var bool |
||
30 | */ |
||
31 | protected $enable_save = false; |
||
32 | |||
33 | /** |
||
34 | * Constructor. |
||
35 | */ |
||
36 | View Code Duplication | public function __construct() { |
|
48 | |||
49 | /** |
||
50 | * Get settings array. |
||
51 | * |
||
52 | * @since 1.8 |
||
53 | * @return array |
||
54 | */ |
||
55 | public function get_settings() { |
||
86 | } |
||
87 | |||
91 |
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.