| 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 |
||
| 121 | function give_is_admin_page( $passed_page = '', $passed_view = '' ) { |
||
| 122 | global $pagenow, $typenow; |
||
| 123 | |||
| 124 | $found = true; |
||
| 125 | $get_query_args = ! empty( $_GET ) ? @array_map( 'strtolower', $_GET ) : array(); |
||
| 126 | |||
| 127 | // Set default argument, if not passed. |
||
| 128 | $query_args = wp_parse_args( $get_query_args, array_fill_keys( array( 'post_type', 'action', 'taxonomy', 'page', 'view', 'tab' ), false ) ); |
||
| 129 | |||
| 130 | switch ( $passed_page ) { |
||
| 131 | case 'categories': |
||
| 132 | case 'tags': |
||
| 133 | $has_view = in_array( $passed_view, array( 'list-table', 'edit', 'new' ), true ); |
||
| 134 | |||
| 135 | if ( |
||
| 136 | ! in_array( $query_args['taxonomy'], array( 'give_forms_category', 'give_forms_tag' ), true ) && |
||
| 137 | 'edit-tags.php' !== $pagenow && |
||
| 138 | ( |
||
| 139 | $has_view || |
||
| 140 | ( |
||
| 141 | ( in_array( $passed_view, array( 'list-table', 'new' ), true ) && 'edit' === $query_args['action'] ) || |
||
| 142 | ( 'edit' !== $passed_view && 'edit' !== $query_args['action'] ) && |
||
| 143 | ! $has_view |
||
| 144 | ) |
||
| 145 | ) |
||
| 146 | ) { |
||
| 147 | $found = false; |
||
| 148 | } |
||
| 149 | break; |
||
| 150 | // Give Donation form page. |
||
| 151 | case 'give_forms': |
||
| 152 | $has_view = in_array( $passed_view, array( 'new', 'list-table', 'edit' ), true ); |
||
| 153 | |||
| 154 | if ( |
||
| 155 | 'give_forms' !== $typenow && |
||
| 156 | ( |
||
| 157 | ( 'list-table' !== $passed_view && 'edit.php' !== $pagenow ) && |
||
| 158 | ( 'edit' !== $passed_view && 'post.php' !== $pagenow ) && |
||
| 159 | ( 'new' !== $passed_view && 'post-new.php' !== $pagenow ) |
||
| 160 | ) || |
||
| 161 | ( |
||
| 162 | ! $has_view && |
||
| 163 | ( 'post-new.php' !== $pagenow && 'give_forms' !== $query_args['post_type'] ) |
||
| 164 | ) |
||
| 165 | ) { |
||
| 166 | $found = false; |
||
| 167 | } |
||
| 168 | break; |
||
| 169 | // Give Donors page. |
||
| 170 | case 'donors': |
||
| 171 | $has_view = array_intersect( array( $passed_view, $query_args['view'] ), array( 'list-table', 'overview', 'notes' ) ); |
||
| 172 | |||
| 173 | if ( |
||
| 174 | ( 'give-donors' !== $query_args['page'] || 'edit.php' !== $pagenow ) && |
||
| 175 | ( |
||
| 176 | ( $passed_view !== $query_args['view'] || ! empty( $has_view ) ) || |
||
| 177 | ( false !== $query_args['view'] && 'list-table' !== $passed_view ) |
||
| 178 | ) |
||
| 179 | ) { |
||
| 180 | $found = false; |
||
| 181 | } |
||
| 182 | break; |
||
| 183 | // Give Donations page. |
||
| 184 | case 'payments': |
||
| 185 | if ( |
||
| 186 | ( 'give-payment-history' !== $query_args['page'] || 'edit.php' !== $pagenow ) && |
||
| 187 | ( |
||
| 188 | ! in_array( $passed_view, array( 'list-table', 'edit' ), true ) || |
||
| 189 | ( |
||
| 190 | ( 'list-table' !== $passed_view && false !== $query_args['view'] ) || |
||
| 191 | ( 'edit' !== $passed_view && 'view-payment-details' !== $query_args['view'] ) |
||
| 192 | ) |
||
| 193 | ) |
||
| 194 | ) { |
||
| 195 | $found = false; |
||
| 196 | } |
||
| 197 | break; |
||
| 198 | case 'reports': |
||
| 199 | case 'settings': |
||
| 200 | case 'addons': |
||
| 201 | // Get current tab. |
||
| 202 | $current_tab = empty( $passed_view ) ? $query_args['tab'] : $passed_view; |
||
| 203 | $give_setting_page = in_array( $query_args['page'], array( 'give-reports', 'give-settings', 'give-addons' ), true ); |
||
| 204 | |||
| 205 | // Check if it's Give Setting page or not. |
||
| 206 | if ( |
||
| 207 | ( 'edit.php' !== $pagenow || ! $give_setting_page ) && |
||
| 208 | ! Give_Admin_Settings::is_setting_page( $current_tab ) |
||
| 209 | ) { |
||
| 210 | $found = false; |
||
| 211 | } |
||
| 212 | break; |
||
| 213 | default: |
||
| 214 | 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; |
||
| 215 | $admin_pages = apply_filters( 'give_admin_pages', array( |
||
| 216 | $give_payments_page, |
||
| 217 | $give_settings_page, |
||
| 218 | $give_reports_page, |
||
| 219 | $give_system_info_page, |
||
| 220 | $give_add_ons_page, |
||
| 221 | $give_settings_export, |
||
| 222 | $give_donors_page, |
||
| 223 | $give_tools_page, |
||
| 224 | 'widgets.php', |
||
| 225 | ) ); |
||
| 226 | |||
| 227 | $found = ( 'give_forms' === $typenow || in_array( $pagenow, array_merge( $admin_pages, array( 'index.php', 'post-new.php', 'post.php' ) ), true ) ) ? true : false; |
||
| 228 | } |
||
| 229 | return (bool) apply_filters( 'give_is_admin_page', $found, $query_args['page'], $query_args['view'], $passed_page, $passed_view ); |
||
| 230 | } |
||
| 231 | |||
| 392 |