Conditions | 47 |
Paths | 52 |
Total Lines | 110 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
139 | function give_is_admin_page( $passed_page = '', $passed_view = '' ) { |
||
140 | global $pagenow, $typenow; |
||
141 | |||
142 | $found = true; |
||
143 | $get_query_args = ! empty( $_GET ) ? @array_map( 'strtolower', $_GET ) : array(); |
||
144 | |||
145 | // Set default argument, if not passed. |
||
146 | $query_args = wp_parse_args( $get_query_args, array_fill_keys( array( 'post_type', 'action', 'taxonomy', 'page', 'view', 'tab' ), false ) ); |
||
147 | |||
148 | switch ( $passed_page ) { |
||
149 | case 'categories': |
||
150 | case 'tags': |
||
151 | $has_view = in_array( $passed_view, array( 'list-table', 'edit', 'new' ), true ); |
||
152 | |||
153 | if ( |
||
154 | ! in_array( $query_args['taxonomy'], array( 'give_forms_category', 'give_forms_tag' ), true ) && |
||
155 | 'edit-tags.php' !== $pagenow && |
||
156 | ( |
||
157 | $has_view || |
||
158 | ( |
||
159 | ( in_array( $passed_view, array( 'list-table', 'new' ), true ) && 'edit' === $query_args['action'] ) || |
||
160 | ( 'edit' !== $passed_view && 'edit' !== $query_args['action'] ) && |
||
161 | ! $has_view |
||
162 | ) |
||
163 | ) |
||
164 | ) { |
||
165 | $found = false; |
||
166 | } |
||
167 | break; |
||
168 | // Give Donation form page. |
||
169 | case 'give_forms': |
||
170 | $has_view = in_array( $passed_view, array( 'new', 'list-table', 'edit' ), true ); |
||
171 | |||
172 | if ( |
||
173 | 'give_forms' !== $typenow && |
||
174 | ( |
||
175 | ( 'list-table' !== $passed_view && 'edit.php' !== $pagenow ) && |
||
176 | ( 'edit' !== $passed_view && 'post.php' !== $pagenow ) && |
||
177 | ( 'new' !== $passed_view && 'post-new.php' !== $pagenow ) |
||
178 | ) || |
||
179 | ( |
||
180 | ! $has_view && |
||
181 | ( 'post-new.php' !== $pagenow && 'give_forms' !== $query_args['post_type'] ) |
||
182 | ) |
||
183 | ) { |
||
184 | $found = false; |
||
185 | } |
||
186 | break; |
||
187 | // Give Donors page. |
||
188 | case 'donors': |
||
189 | $has_view = array_intersect( array( $passed_view, $query_args['view'] ), array( 'list-table', 'overview', 'notes' ) ); |
||
190 | |||
191 | if ( |
||
192 | ( 'give-donors' !== $query_args['page'] || 'edit.php' !== $pagenow ) && |
||
193 | ( |
||
194 | ( $passed_view !== $query_args['view'] || ! empty( $has_view ) ) || |
||
195 | ( false !== $query_args['view'] && 'list-table' !== $passed_view ) |
||
196 | ) |
||
197 | ) { |
||
198 | $found = false; |
||
199 | } |
||
200 | break; |
||
201 | // Give Donations page. |
||
202 | case 'payments': |
||
203 | if ( |
||
204 | ( 'give-payment-history' !== $query_args['page'] || 'edit.php' !== $pagenow ) && |
||
205 | ( |
||
206 | ! in_array( $passed_view, array( 'list-table', 'edit' ), true ) || |
||
207 | ( |
||
208 | ( 'list-table' !== $passed_view && false !== $query_args['view'] ) || |
||
209 | ( 'edit' !== $passed_view && 'view-payment-details' !== $query_args['view'] ) |
||
210 | ) |
||
211 | ) |
||
212 | ) { |
||
213 | $found = false; |
||
214 | } |
||
215 | break; |
||
216 | case 'reports': |
||
217 | case 'settings': |
||
218 | case 'addons': |
||
219 | // Get current tab. |
||
220 | $current_tab = empty( $passed_view ) ? $query_args['tab'] : $passed_view; |
||
221 | $give_setting_page = in_array( $query_args['page'], array( 'give-reports', 'give-settings', 'give-addons' ), true ); |
||
222 | |||
223 | // Check if it's Give Setting page or not. |
||
224 | if ( |
||
225 | ( 'edit.php' !== $pagenow || ! $give_setting_page ) && |
||
226 | ! Give_Admin_Settings::is_setting_page( $current_tab ) |
||
227 | ) { |
||
228 | $found = false; |
||
229 | } |
||
230 | break; |
||
231 | default: |
||
232 | global $give_payments_page, $give_settings_page, $give_reports_page, $give_system_info_page, $give_add_ons_page, $give_settings_export, $give_donors_page, $give_tools_page; |
||
233 | $admin_pages = apply_filters( 'give_admin_pages', array( |
||
234 | $give_payments_page, |
||
235 | $give_settings_page, |
||
236 | $give_reports_page, |
||
237 | $give_system_info_page, |
||
238 | $give_add_ons_page, |
||
239 | $give_settings_export, |
||
240 | $give_donors_page, |
||
241 | $give_tools_page, |
||
242 | 'widgets.php', |
||
243 | ) ); |
||
244 | |||
245 | $found = ( 'give_forms' === $typenow || in_array( $pagenow, array_merge( $admin_pages, array( 'index.php', 'post-new.php', 'post.php' ) ), true ) ) ? true : false; |
||
246 | } |
||
247 | return (bool) apply_filters( 'give_is_admin_page', $found, $query_args['page'], $query_args['view'], $passed_page, $passed_view ); |
||
248 | } |
||
249 | |||
409 |
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.