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 |
||
15 | class Jetpack_Admin_Menu extends Admin_Menu { |
||
16 | |||
17 | /** |
||
18 | * Jetpack_Admin_Menu constructor. |
||
19 | */ |
||
20 | public function __construct() { |
||
26 | |||
27 | /** |
||
28 | * Dequeues unnecessary scripts. |
||
29 | */ |
||
30 | public function dequeue_scripts() { |
||
33 | |||
34 | /** |
||
35 | * Determines whether the current locale is right-to-left (RTL). |
||
36 | * |
||
37 | * Performs the check against the current locale set on the WordPress.com's account settings. |
||
38 | * See `Masterbar::__construct` in `modules/masterbar/masterbar/class-masterbar.php`. |
||
39 | */ |
||
40 | public function is_rtl() { |
||
43 | |||
44 | /** |
||
45 | * Create the desired menu output. |
||
46 | */ |
||
47 | public function reregister_menu_items() { |
||
64 | |||
65 | /** |
||
66 | * Whether to use wp-admin pages rather than Calypso. |
||
67 | * |
||
68 | * @return bool |
||
69 | */ |
||
70 | public function should_link_to_wp_admin() { |
||
74 | |||
75 | /** |
||
76 | * Adds Posts menu. |
||
77 | * |
||
78 | * @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso). |
||
79 | */ |
||
80 | public function add_posts_menu( $wp_admin = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
84 | |||
85 | /** |
||
86 | * Adds Media menu. |
||
87 | * |
||
88 | * @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso). |
||
89 | */ |
||
90 | public function add_media_menu( $wp_admin = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
93 | |||
94 | /** |
||
95 | * Adds Page menu. |
||
96 | * |
||
97 | * @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso). |
||
98 | */ |
||
99 | public function add_page_menu( $wp_admin = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
103 | |||
104 | /** |
||
105 | * Adds a custom post type menu. |
||
106 | * |
||
107 | * @param string $post_type Custom post type. |
||
108 | * @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso). |
||
109 | */ |
||
110 | public function add_custom_post_type_menu( $post_type, $wp_admin = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
131 | |||
132 | /** |
||
133 | * Adds Comments menu. |
||
134 | * |
||
135 | * @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso). |
||
136 | */ |
||
137 | public function add_comments_menu( $wp_admin = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
140 | |||
141 | /** |
||
142 | * Adds Feedback menu. |
||
143 | */ |
||
144 | public function add_feedback_menu() { |
||
160 | |||
161 | /** |
||
162 | * Adds Jetpack menu. |
||
163 | */ |
||
164 | public function add_jetpack_menu() { |
||
178 | |||
179 | /** |
||
180 | * Adds Appearance menu. |
||
181 | * |
||
182 | * @param bool $wp_admin_themes Optional. Whether Themes link should point to Calypso or wp-admin. Default false (Calypso). |
||
183 | * @param bool $wp_admin_customize Optional. Whether Customize link should point to Calypso or wp-admin. Default false (Calypso). |
||
184 | */ |
||
185 | public function add_appearance_menu( $wp_admin_themes = false, $wp_admin_customize = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
191 | |||
192 | /** |
||
193 | * Adds Plugins menu. |
||
194 | * |
||
195 | * @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso). |
||
196 | */ |
||
197 | public function add_plugins_menu( $wp_admin = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
200 | |||
201 | /** |
||
202 | * Adds Users menu. |
||
203 | * |
||
204 | * @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso). |
||
205 | */ |
||
206 | View Code Duplication | public function add_users_menu( $wp_admin = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
213 | |||
214 | /** |
||
215 | * Adds Tools menu. |
||
216 | * |
||
217 | * @param bool $wp_admin_import Optional. Whether Import link should point to Calypso or wp-admin. Default false (Calypso). |
||
218 | * @param bool $wp_admin_export Optional. Whether Export link should point to Calypso or wp-admin. Default false (Calypso). |
||
219 | */ |
||
220 | public function add_tools_menu( $wp_admin_import = false, $wp_admin_export = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
233 | |||
234 | /** |
||
235 | * Adds Settings menu. |
||
236 | * |
||
237 | * @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso). |
||
238 | */ |
||
239 | public function add_options_menu( $wp_admin = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
242 | |||
243 | /** |
||
244 | * Adds WP Admin menu. |
||
245 | */ |
||
246 | public function add_wp_admin_menu() { |
||
257 | } |
||
258 |