| Conditions | 16 |
| Paths | 56 |
| Total Lines | 104 |
| Lines | 7 |
| Ratio | 6.73 % |
| 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 |
||
| 58 | function authorize( $data = array() ) { |
||
| 59 | $redirect = isset( $data['redirect'] ) ? esc_url_raw( (string) $data['redirect'] ) : ''; |
||
| 60 | |||
| 61 | $jetpack_unique_connection = Jetpack_Options::get_option( 'unique_connection' ); |
||
| 62 | // Checking if site has been active/connected previously before recording unique connection |
||
| 63 | if ( ! $jetpack_unique_connection ) { |
||
| 64 | // jetpack_unique_connection option has never been set |
||
| 65 | $jetpack_unique_connection = array( |
||
| 66 | 'connected' => 0, |
||
| 67 | 'disconnected' => 0, |
||
| 68 | 'version' => '3.6.1', |
||
| 69 | ); |
||
| 70 | |||
| 71 | update_option( 'jetpack_unique_connection', $jetpack_unique_connection ); |
||
| 72 | |||
| 73 | //track unique connection |
||
| 74 | $jetpack = $this->get_jetpack(); |
||
| 75 | |||
| 76 | $jetpack->stat( 'connections', 'unique-connection' ); |
||
| 77 | $jetpack->do_stats( 'server_side' ); |
||
| 78 | } |
||
| 79 | |||
| 80 | // increment number of times connected |
||
| 81 | $jetpack_unique_connection['connected'] += 1; |
||
| 82 | Jetpack_Options::update_option( 'unique_connection', $jetpack_unique_connection ); |
||
| 83 | |||
| 84 | $roles = new Roles(); |
||
| 85 | $role = $roles->translate_current_user_to_role(); |
||
| 86 | |||
| 87 | if ( ! $role ) { |
||
| 88 | return new Jetpack_Error( 'no_role', 'Invalid request.', 400 ); |
||
| 89 | } |
||
| 90 | |||
| 91 | $cap = $roles->translate_role_to_cap( $role ); |
||
| 92 | if ( ! $cap ) { |
||
| 93 | return new Jetpack_Error( 'no_cap', 'Invalid request.', 400 ); |
||
| 94 | } |
||
| 95 | |||
| 96 | if ( ! empty( $data['error'] ) ) { |
||
| 97 | return new Jetpack_Error( $data['error'], 'Error included in the request.', 400 ); |
||
| 98 | } |
||
| 99 | |||
| 100 | if ( ! isset( $data['state'] ) ) { |
||
| 101 | return new Jetpack_Error( 'no_state', 'Request must include state.', 400 ); |
||
| 102 | } |
||
| 103 | |||
| 104 | if ( ! ctype_digit( $data['state'] ) ) { |
||
| 105 | return new Jetpack_Error( $data['error'], 'State must be an integer.', 400 ); |
||
| 106 | } |
||
| 107 | |||
| 108 | $current_user_id = get_current_user_id(); |
||
| 109 | if ( $current_user_id != $data['state'] ) { |
||
| 110 | return new Jetpack_Error( 'wrong_state', 'State does not match current user.', 400 ); |
||
| 111 | } |
||
| 112 | |||
| 113 | if ( empty( $data['code'] ) ) { |
||
| 114 | return new Jetpack_Error( 'no_code', 'Request must include an authorization code.', 400 ); |
||
| 115 | } |
||
| 116 | |||
| 117 | $token = $this->get_token( $data ); |
||
| 118 | |||
| 119 | View Code Duplication | if ( is_wp_error( $token ) ) { |
|
| 120 | $code = $token->get_error_code(); |
||
| 121 | if ( empty( $code ) ) { |
||
| 122 | $code = 'invalid_token'; |
||
| 123 | } |
||
| 124 | return new Jetpack_Error( $code, $token->get_error_message(), 400 ); |
||
| 125 | } |
||
| 126 | |||
| 127 | if ( ! $token ) { |
||
| 128 | return new Jetpack_Error( 'no_token', 'Error generating token.', 400 ); |
||
| 129 | } |
||
| 130 | |||
| 131 | $is_master_user = ! Jetpack::is_active(); |
||
| 132 | |||
| 133 | Jetpack::update_user_token( $current_user_id, sprintf( '%s.%d', $token, $current_user_id ), $is_master_user ); |
||
| 134 | |||
| 135 | if ( ! $is_master_user ) { |
||
| 136 | Jetpack::state( 'message', 'linked' ); |
||
| 137 | // Don't activate anything since we are just connecting a user. |
||
| 138 | return 'linked'; |
||
| 139 | } |
||
| 140 | |||
| 141 | // If this site has been through the Jetpack Onboarding flow, delete the onboarding token |
||
| 142 | Jetpack::invalidate_onboarding_token(); |
||
| 143 | |||
| 144 | // If redirect_uri is SSO, ensure SSO module is enabled |
||
| 145 | parse_str( parse_url( $data['redirect_uri'], PHP_URL_QUERY ), $redirect_options ); |
||
| 146 | |||
| 147 | /** This filter is documented in class.jetpack-cli.php */ |
||
| 148 | $jetpack_start_enable_sso = apply_filters( 'jetpack_start_enable_sso', true ); |
||
| 149 | |||
| 150 | $activate_sso = ( |
||
| 151 | isset( $redirect_options['action'] ) && |
||
| 152 | 'jetpack-sso' === $redirect_options['action'] && |
||
| 153 | $jetpack_start_enable_sso |
||
| 154 | ); |
||
| 155 | |||
| 156 | $do_redirect_on_error = ( 'client' === $data['auth_type'] ); |
||
| 157 | |||
| 158 | Jetpack::handle_post_authorization_actions( $activate_sso, $do_redirect_on_error ); |
||
| 159 | |||
| 160 | return 'authorized'; |
||
| 161 | } |
||
| 162 | |||
| 302 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.