| Conditions | 47 |
| Paths | 52 |
| Total Lines | 97 |
| 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 = isset( $_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 ( ! in_array( $query_args['taxonomy'], array( 'give_forms_category', 'give_forms_tag' ), true ) && 'edit-tags.php' !== $pagenow |
||
| 136 | && ( $has_view || |
||
| 137 | ( |
||
| 138 | ( in_array( $passed_view, array( 'list-table', 'new' ), true ) && 'edit' === $query_args['action'] ) || |
||
| 139 | ( 'edit' !== $passed_view && 'edit' !== $query_args['action'] ) |
||
| 140 | && ! $has_view |
||
| 141 | ) |
||
| 142 | ) |
||
| 143 | ) { |
||
| 144 | $found = false; |
||
| 145 | } |
||
| 146 | break; |
||
| 147 | // Give Donation form page. |
||
| 148 | case 'give_forms': |
||
| 149 | $has_view = in_array( $passed_view, array( 'new', 'list-table', 'edit' ), true ); |
||
| 150 | |||
| 151 | if ( 'give_forms' !== $typenow |
||
| 152 | && ( ( 'list-table' !== $passed_view && 'edit.php' !== $pagenow ) && |
||
| 153 | ( 'edit' !== $passed_view && 'post.php' !== $pagenow ) && |
||
| 154 | ( 'new' !== $passed_view && 'post-new.php' !== $pagenow ) ) |
||
| 155 | || ( ! $has_view && ( 'post-new.php' !== $pagenow && 'give_forms' !== $query_args['post_type'] ) ) |
||
| 156 | ) { |
||
| 157 | $found = false; |
||
| 158 | } |
||
| 159 | break; |
||
| 160 | // Give Donors page. |
||
| 161 | case 'donors': |
||
| 162 | $has_view = array_intersect( array( $passed_view, $query_args['view'] ), array( 'list-table', 'overview', 'notes' ) ); |
||
| 163 | |||
| 164 | if ( |
||
| 165 | ( 'give-donors' !== $query_args['page'] || 'edit.php' !== $pagenow ) |
||
| 166 | && ( ( $passed_view !== $query_args['view'] || ! empty( $has_view ) ) || |
||
| 167 | ( false !== $query_args['view'] && 'list-table' !== $passed_view ) |
||
| 168 | ) |
||
| 169 | ) { |
||
| 170 | $found = false; |
||
| 171 | } |
||
| 172 | break; |
||
| 173 | // Give Donations page. |
||
| 174 | case 'payments' : |
||
| 175 | if ( ( 'give-payment-history' !== $query_args['page'] || 'edit.php' !== $pagenow ) |
||
| 176 | && ( ! in_array( $passed_view, array( 'list-table', 'edit' ), true ) || |
||
| 177 | ( |
||
| 178 | ( 'list-table' !== $passed_view && false !== $query_args['view'] ) || |
||
| 179 | ( 'edit' !== $passed_view && 'view-payment-details' !== $query_args['view'] ) |
||
| 180 | ) |
||
| 181 | ) |
||
| 182 | ) { |
||
| 183 | $found = false; |
||
| 184 | } |
||
| 185 | break; |
||
| 186 | case 'reports': |
||
| 187 | case 'settings': |
||
| 188 | case 'addons': |
||
| 189 | // Get current tab. |
||
| 190 | $current_tab = empty( $passed_view ) ? $query_args['tab'] : $passed_view; |
||
| 191 | $give_setting_page = in_array( $query_args['page'], array( 'give-reports', 'give-settings', 'give-addons' ), true ); |
||
| 192 | |||
| 193 | // Check if it's Give Setting page or not. |
||
| 194 | if ( ( 'edit.php' !== $pagenow || ! $give_setting_page ) |
||
| 195 | && ! Give_Admin_Settings::is_setting_page( $current_tab ) |
||
| 196 | ) { |
||
| 197 | $found = false; |
||
| 198 | } |
||
| 199 | break; |
||
| 200 | default: |
||
| 201 | 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; |
||
| 202 | $admin_pages = apply_filters( 'give_admin_pages', array( |
||
| 203 | $give_payments_page, |
||
| 204 | $give_settings_page, |
||
| 205 | $give_reports_page, |
||
| 206 | $give_system_info_page, |
||
| 207 | $give_add_ons_page, |
||
| 208 | $give_settings_export, |
||
| 209 | $give_donors_page, |
||
| 210 | $give_tools_page, |
||
| 211 | 'widgets.php', |
||
| 212 | ) ); |
||
| 213 | |||
| 214 | $found = ( 'give_forms' === $typenow || in_array( $pagenow, array_merge( $admin_pages, array( 'index.php', 'post-new.php', 'post.php' ) ), true ) ) ? true : false; |
||
| 215 | } |
||
| 216 | return (bool) apply_filters( 'give_is_admin_page', $found, $query_args['page'], $query_args['view'], $passed_page, $passed_view ); |
||
| 217 | } |
||
| 218 | |||
| 377 | add_filter( 'display_post_states', 'give_add_display_page_states', 10, 2 ); |