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_Addon extends Give_Settings_Page { |
||
24 | /** |
||
25 | * Constructor. |
||
26 | */ |
||
27 | public function __construct() { |
||
33 | |||
34 | /** |
||
35 | * Default setting tab. |
||
36 | * |
||
37 | * @since 1.8 |
||
38 | * @param $setting_tab |
||
39 | * @return string |
||
40 | */ |
||
41 | View Code Duplication | function set_default_setting_tab( $setting_tab ) { |
|
50 | |||
51 | /** |
||
52 | * Add this page to settings. |
||
53 | * |
||
54 | * @since 1.8 |
||
55 | * @param array $pages Lst of pages. |
||
56 | * @return array |
||
57 | */ |
||
58 | public function add_settings_page( $pages ) { |
||
67 | |||
68 | /** |
||
69 | * Get settings array. |
||
70 | * |
||
71 | * @since 1.8 |
||
72 | * @return array |
||
73 | */ |
||
74 | public function get_settings() { |
||
94 | } |
||
95 | |||
99 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.