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 | * Create the desired menu output. |
||
36 | */ |
||
37 | public function reregister_menu_items() { |
||
54 | |||
55 | /** |
||
56 | * Whether to use wp-admin pages rather than Calypso. |
||
57 | * |
||
58 | * @return bool |
||
59 | */ |
||
60 | public function should_link_to_wp_admin() { |
||
64 | |||
65 | /** |
||
66 | * Adds Posts menu. |
||
67 | * |
||
68 | * @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso). |
||
69 | */ |
||
70 | public function add_posts_menu( $wp_admin = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
74 | |||
75 | /** |
||
76 | * Adds Media 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_media_menu( $wp_admin = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
83 | |||
84 | /** |
||
85 | * Adds Page menu. |
||
86 | * |
||
87 | * @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso). |
||
88 | */ |
||
89 | public function add_page_menu( $wp_admin = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
93 | |||
94 | /** |
||
95 | * Adds a custom post type menu. |
||
96 | * |
||
97 | * @param string $post_type Custom post type. |
||
98 | * @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso). |
||
99 | */ |
||
100 | public function add_custom_post_type_menu( $post_type, $wp_admin = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
121 | |||
122 | /** |
||
123 | * Adds Comments menu. |
||
124 | * |
||
125 | * @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso). |
||
126 | */ |
||
127 | public function add_comments_menu( $wp_admin = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
130 | |||
131 | /** |
||
132 | * Adds Feedback menu. |
||
133 | */ |
||
134 | public function add_feedback_menu() { |
||
150 | |||
151 | /** |
||
152 | * Adds Jetpack menu. |
||
153 | */ |
||
154 | public function add_jetpack_menu() { |
||
168 | |||
169 | /** |
||
170 | * Adds Appearance menu. |
||
171 | * |
||
172 | * @param bool $wp_admin_themes Optional. Whether Themes link should point to Calypso or wp-admin. Default false (Calypso). |
||
173 | * @param bool $wp_admin_customize Optional. Whether Customize link should point to Calypso or wp-admin. Default false (Calypso). |
||
174 | */ |
||
175 | public function add_appearance_menu( $wp_admin_themes = false, $wp_admin_customize = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
181 | |||
182 | /** |
||
183 | * Adds Plugins menu. |
||
184 | * |
||
185 | * @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso). |
||
186 | */ |
||
187 | public function add_plugins_menu( $wp_admin = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
190 | |||
191 | /** |
||
192 | * Adds Users menu. |
||
193 | * |
||
194 | * @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso). |
||
195 | */ |
||
196 | View Code Duplication | public function add_users_menu( $wp_admin = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
203 | |||
204 | /** |
||
205 | * Adds Tools menu. |
||
206 | * |
||
207 | * @param bool $wp_admin_import Optional. Whether Import link should point to Calypso or wp-admin. Default false (Calypso). |
||
208 | * @param bool $wp_admin_export Optional. Whether Export link should point to Calypso or wp-admin. Default false (Calypso). |
||
209 | */ |
||
210 | public function add_tools_menu( $wp_admin_import = false, $wp_admin_export = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
223 | |||
224 | /** |
||
225 | * Adds Settings menu. |
||
226 | * |
||
227 | * @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso). |
||
228 | */ |
||
229 | public function add_options_menu( $wp_admin = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
232 | |||
233 | /** |
||
234 | * Adds WP Admin menu. |
||
235 | */ |
||
236 | public function add_wp_admin_menu() { |
||
247 | } |
||
248 |