| Conditions | 14 |
| Paths | 102 |
| Total Lines | 82 |
| Code Lines | 34 |
| 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 |
||
| 30 | public static function index() { |
||
| 31 | |||
| 32 | // Only execute for non logged in users. |
||
| 33 | if ( is_user_logged_in() ) { |
||
| 34 | return; |
||
| 35 | } |
||
| 36 | |||
| 37 | $queried_id = get_queried_object_id(); |
||
| 38 | |||
| 39 | $current_post = get_post( absint( $queried_id ) ); |
||
| 40 | |||
| 41 | $login_page_id = absint( get_option( 'subway_login_page' ) ); |
||
| 42 | |||
| 43 | $excluded_page = Options::get_public_post_ids(); |
||
| 44 | |||
| 45 | // Already escaped inside 'subway_get_redirect_page_url'. |
||
| 46 | $redirect_page = Options::get_redirect_page_url(); // WPCS XSS OK. |
||
| 47 | |||
| 48 | // Exit if site is public. |
||
| 49 | if ( Options::is_public_site() ) { |
||
| 50 | return; |
||
| 51 | } |
||
| 52 | |||
| 53 | // Check if redirect page is empty or not. |
||
| 54 | if ( empty( $redirect_page ) ) { |
||
| 55 | return; |
||
| 56 | } |
||
| 57 | |||
| 58 | // Check if buddypress activate page. |
||
| 59 | if ( function_exists( 'bp_is_activation_page' ) ) { |
||
| 60 | if ( bp_is_activation_page() ) { |
||
| 61 | return; |
||
| 62 | } |
||
| 63 | } |
||
| 64 | |||
| 65 | // Check if buddypress registration page. |
||
| 66 | if ( function_exists( 'bp_is_register_page' ) ) { |
||
| 67 | if ( bp_is_register_page() ) { |
||
| 68 | return; |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | // Assign 0 value to empty $post->ID to prevent exception. |
||
| 73 | // This applies to custom WordPress pages such as BP Members Page and Groups. |
||
| 74 | if ( empty( $current_post ) ) { |
||
| 75 | $current_post = new \stdclass; |
||
| 76 | $current_post->ID = 0; |
||
| 77 | } |
||
| 78 | |||
| 79 | $current_page_id = absint( $current_post->ID ); |
||
| 80 | |||
| 81 | // Check if $current_page_id && $selected_blog_id is equal to each other. |
||
| 82 | // If that is the case, get the page ID instead of global $post->ID that the query returns. |
||
| 83 | // The ID of the first post object inside the loop is not correct. |
||
| 84 | $blog_id = absint( get_option( 'page_for_posts' ) ); |
||
| 85 | |||
| 86 | if ( is_home() ) { |
||
| 87 | if ( $blog_id === $login_page_id ) { |
||
| 88 | $current_page_id = $blog_id; |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 92 | // Only execute the script for non-loggedin visitors. |
||
| 93 | if ( ! is_user_logged_in() ) { |
||
| 94 | |||
| 95 | if ( $current_page_id !== $login_page_id ) { |
||
| 96 | |||
| 97 | if ( ! in_array( $current_page_id, $excluded_page, true ) ) { |
||
| 98 | |||
| 99 | wp_safe_redirect( |
||
| 100 | add_query_arg( |
||
| 101 | array( '_redirected' => 'yes' ), |
||
| 102 | $redirect_page |
||
| 103 | ) |
||
| 104 | ); |
||
| 105 | |||
| 106 | die(); |
||
| 107 | |||
| 108 | } |
||
| 109 | } |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 115 |
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.