| Conditions | 23 |
| Paths | 412 |
| 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 |
||
| 44 | public static function index() |
||
| 45 | { |
||
| 46 | |||
| 47 | // Additional filter for custom pages, taxonomy, links, parameterized urls, etc. |
||
| 48 | // Callback function/method must return true (boolean) to disable redirect. |
||
| 49 | $should_exit = apply_filters( 'subway/classes/subway-page-redirect/index/before-page-redirect', false ); |
||
| 50 | |||
| 51 | if ( $should_exit ) { |
||
| 52 | return; |
||
| 53 | } |
||
| 54 | |||
| 55 | // Only execute for non logged in users. |
||
| 56 | if (is_user_logged_in() ) { |
||
| 57 | return; |
||
| 58 | } |
||
| 59 | |||
| 60 | $is_private = false; |
||
| 61 | |||
| 62 | $queried_id = get_queried_object_id(); |
||
| 63 | |||
| 64 | $current_post = get_post(absint($queried_id)); |
||
| 65 | |||
| 66 | $login_page_id = absint(get_option('subway_login_page')); |
||
| 67 | |||
| 68 | $excluded_page = Options::getPublicPostsIdentifiers(); |
||
| 69 | |||
| 70 | // Already escaped inside 'subway_get_redirect_page_url'. |
||
| 71 | $redirect_page = Options::getRedirectPageUrl(); // WPCS XSS OK. |
||
| 72 | |||
| 73 | if ( !empty( $current_post ) ) { |
||
| 74 | $is_private = Metabox::isPostPrivate( $current_post->ID ); |
||
| 75 | } |
||
| 76 | |||
| 77 | // do_action( 'subway/classes/subway-page-redirect/index/before_page_redirect' ); |
||
| 78 | |||
| 79 | // Turn off if is in 'wc-ajax' (woocommerce) |
||
| 80 | if ( function_exists( 'is_ajax') ) { |
||
| 81 | if ( is_ajax() ) { |
||
| 82 | return; |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | // Same for normal ajax requests. |
||
| 87 | if ( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
||
| 88 | return; |
||
| 89 | } |
||
| 90 | |||
| 91 | // Exit if site is public. |
||
| 92 | if ( Options::isPublicSite() ) { |
||
| 93 | return; |
||
| 94 | } |
||
| 95 | |||
| 96 | // Check if redirect page is empty or not. |
||
| 97 | if ( empty( $redirect_page ) ) { |
||
| 98 | return; |
||
| 99 | } |
||
| 100 | |||
| 101 | // Check if buddypress activate page. |
||
| 102 | if (function_exists('bp_is_activation_page') ) { |
||
| 103 | if (bp_is_activation_page() ) { |
||
| 104 | return; |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 108 | // Check if buddypress registration page. |
||
| 109 | if (function_exists('bp_is_register_page') ) { |
||
| 110 | if (bp_is_register_page() ) { |
||
| 111 | return; |
||
| 112 | } |
||
| 113 | } |
||
| 114 | |||
| 115 | // Assign 0 value to empty $post->ID to prevent exception. |
||
| 116 | // This applies to custom WordPress pages such as BP Members Page and Groups. |
||
| 117 | if (empty($current_post) ) { |
||
| 118 | $current_post = new \stdclass; |
||
| 119 | $current_post->ID = 0; |
||
| 120 | } |
||
| 121 | |||
| 122 | $current_page_id = absint($current_post->ID); |
||
| 123 | |||
| 124 | // Check if $current_page_id && $selected_blog_id is equal to each other. |
||
| 125 | // Get the page ID instead of global $post->ID that the query returns. |
||
| 126 | // The ID of the first post object inside the loop is not correct. |
||
| 127 | $blog_id = absint(get_option('page_for_posts')); |
||
| 128 | |||
| 129 | if (is_home() ) { |
||
| 130 | if ($blog_id === $login_page_id ) { |
||
| 131 | $current_page_id = $blog_id; |
||
| 132 | } |
||
| 133 | } |
||
| 134 | |||
| 135 | // Only execute the script for non-loggedin visitors. |
||
| 136 | if ( ! is_user_logged_in() ) { |
||
| 137 | |||
| 138 | if ($current_page_id !== $login_page_id ) { |
||
| 139 | |||
| 140 | if ( ! in_array( $current_page_id, $excluded_page, true ) || in_array( $current_page_id, $excluded_page, true ) && true === $is_private ) { |
||
| 141 | |||
| 142 | wp_safe_redirect( |
||
| 143 | add_query_arg( |
||
| 144 | array( '_redirected' => 'yes' ), |
||
| 145 | $redirect_page |
||
| 146 | ) |
||
| 147 | ); |
||
| 148 | |||
| 149 | Helpers::close(); |
||
| 150 | } |
||
| 151 | } |
||
| 152 | } |
||
| 153 | } |
||
| 154 | |||
| 156 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.