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