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 |
||
10 | class WETU_Importer { |
||
11 | |||
12 | /** |
||
13 | * Holds class instance |
||
14 | * |
||
15 | * @since 1.0.0 |
||
16 | * |
||
17 | * @var object|Module_Template |
||
18 | */ |
||
19 | protected static $instance = null; |
||
20 | |||
21 | /** |
||
22 | * The slug for this plugin |
||
23 | * |
||
24 | * @since 0.0.1 |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | public $plugin_slug = 'wetu-importer'; |
||
29 | |||
30 | /** |
||
31 | * The options for the plugin |
||
32 | * |
||
33 | * @since 0.0.1 |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | public $options = false; |
||
38 | |||
39 | /** |
||
40 | * The url to import images from WETU |
||
41 | * |
||
42 | * @since 0.0.1 |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | public $import_scaling_url = false; |
||
47 | |||
48 | /** |
||
49 | * scale the images on import or not |
||
50 | * |
||
51 | * @since 0.0.1 |
||
52 | * |
||
53 | * @var boolean |
||
54 | */ |
||
55 | public $scale_images = false; |
||
56 | |||
57 | /** |
||
58 | * The WETU API Key |
||
59 | */ |
||
60 | public $api_key = false; |
||
61 | |||
62 | /** |
||
63 | * The WETU API Username |
||
64 | */ |
||
65 | public $api_username = false; |
||
66 | |||
67 | /** |
||
68 | * The WETU API Password |
||
69 | */ |
||
70 | public $api_password = false; |
||
71 | |||
72 | /** |
||
73 | * Initialize the plugin by setting localization, filters, and administration functions. |
||
74 | * |
||
75 | * @since 1.0.0 |
||
76 | * |
||
77 | * @access private |
||
78 | */ |
||
79 | public function __construct() { |
||
92 | |||
93 | /** |
||
94 | * On plugin activation |
||
95 | * |
||
96 | * @since 1.0.0 |
||
97 | */ |
||
98 | public static function register_activation_hook() { |
||
101 | |||
102 | /** |
||
103 | * Check if the PHP version is compatible. |
||
104 | * |
||
105 | * @since 1.0.0 |
||
106 | */ |
||
107 | public static function compatible_version() { |
||
114 | |||
115 | /** |
||
116 | * The backup sanity check, in case the plugin is activated in a weird way, |
||
117 | * or the versions change after activation. |
||
118 | * |
||
119 | * @since 1.0.0 |
||
120 | */ |
||
121 | public function compatible_version_check() { |
||
133 | |||
134 | /** |
||
135 | * Display the notice related with the older version from PHP. |
||
136 | * |
||
137 | * @since 1.0.0 |
||
138 | */ |
||
139 | public function compatible_version_notice() { |
||
144 | |||
145 | /** |
||
146 | * The primary sanity check, automatically disable the plugin on activation if it doesn't |
||
147 | * meet minimum requirements. |
||
148 | * |
||
149 | * @since 1.0.0 |
||
150 | */ |
||
151 | public static function compatible_version_check_on_activation() { |
||
157 | |||
158 | /** |
||
159 | * Sets the variables used throughout the plugin. |
||
160 | */ |
||
161 | public function set_variables() { |
||
200 | |||
201 | /** |
||
202 | * Load the plugin text domain for translation. |
||
203 | * |
||
204 | * @since 1.0.0 |
||
205 | */ |
||
206 | public function load_plugin_textdomain() { |
||
209 | } |
||
210 | $wetu_importer = new WETU_Importer(); |
||
211 |
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.