| Conditions | 17 |
| Paths | 104 |
| Total Lines | 126 |
| Code Lines | 74 |
| Lines | 0 |
| Ratio | 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 |
||
| 9 | function authorize() { |
||
| 10 | $data = stripslashes_deep( $_GET ); |
||
| 11 | $redirect = isset( $data['redirect'] ) ? esc_url_raw( (string) $data['redirect'] ) : ''; |
||
| 12 | |||
| 13 | $jetpack_unique_connection = Jetpack_Options::get_option( 'unique_connection' ); |
||
| 14 | // Checking if site has been active/connected previously before recording unique connection |
||
| 15 | if ( ! $jetpack_unique_connection ) { |
||
| 16 | // jetpack_unique_connection option has never been set |
||
| 17 | $jetpack_unique_connection = array( |
||
| 18 | 'connected' => 0, |
||
| 19 | 'disconnected' => 0, |
||
| 20 | 'version' => '3.6.1' |
||
| 21 | ); |
||
| 22 | |||
| 23 | update_option( 'jetpack_unique_connection', $jetpack_unique_connection ); |
||
| 24 | |||
| 25 | //track unique connection |
||
| 26 | $jetpack = Jetpack::init(); |
||
| 27 | |||
| 28 | $jetpack->stat( 'connections', 'unique-connection' ); |
||
| 29 | $jetpack->do_stats( 'server_side' ); |
||
| 30 | } |
||
| 31 | |||
| 32 | // increment number of times connected |
||
| 33 | $jetpack_unique_connection['connected'] += 1; |
||
| 34 | Jetpack_Options::update_option( 'unique_connection', $jetpack_unique_connection ); |
||
| 35 | |||
| 36 | do { |
||
| 37 | $jetpack = $this->get_jetpack(); |
||
| 38 | $role = $jetpack->translate_current_user_to_role(); |
||
| 39 | |||
| 40 | if ( !$role ) { |
||
| 41 | Jetpack::state( 'error', 'no_role' ); |
||
| 42 | break; |
||
| 43 | } |
||
| 44 | |||
| 45 | $cap = $jetpack->translate_role_to_cap( $role ); |
||
| 46 | if ( !$cap ) { |
||
| 47 | Jetpack::state( 'error', 'no_cap' ); |
||
| 48 | break; |
||
| 49 | } |
||
| 50 | |||
| 51 | $this->check_admin_referer( "jetpack-authorize_{$role}_{$redirect}" ); |
||
| 52 | |||
| 53 | if ( !empty( $data['error'] ) ) { |
||
| 54 | Jetpack::state( 'error', $data['error'] ); |
||
| 55 | break; |
||
| 56 | } |
||
| 57 | |||
| 58 | if ( empty( $data['state'] ) ) { |
||
| 59 | Jetpack::state( 'error', 'no_state' ); |
||
| 60 | break; |
||
| 61 | } |
||
| 62 | |||
| 63 | if ( !ctype_digit( $data['state'] ) ) { |
||
| 64 | Jetpack::state( 'error', 'invalid_state' ); |
||
| 65 | break; |
||
| 66 | } |
||
| 67 | |||
| 68 | $current_user_id = get_current_user_id(); |
||
| 69 | if ( $current_user_id != $data['state'] ) { |
||
| 70 | Jetpack::state( 'error', 'wrong_state' ); |
||
| 71 | break; |
||
| 72 | } |
||
| 73 | |||
| 74 | if ( empty( $data['code'] ) ) { |
||
| 75 | Jetpack::state( 'error', 'no_code' ); |
||
| 76 | break; |
||
| 77 | } |
||
| 78 | |||
| 79 | $token = $this->get_token( $data ); |
||
| 80 | |||
| 81 | if ( is_wp_error( $token ) ) { |
||
| 82 | if ( $error = $token->get_error_code() ) |
||
| 83 | Jetpack::state( 'error', $error ); |
||
| 84 | else |
||
| 85 | Jetpack::state( 'error', 'invalid_token' ); |
||
| 86 | |||
| 87 | Jetpack::state( 'error_description', $token->get_error_message() ); |
||
| 88 | |||
| 89 | break; |
||
| 90 | } |
||
| 91 | |||
| 92 | if ( !$token ) { |
||
| 93 | Jetpack::state( 'error', 'no_token' ); |
||
| 94 | break; |
||
| 95 | } |
||
| 96 | |||
| 97 | $is_master_user = ! Jetpack::is_active(); |
||
| 98 | |||
| 99 | Jetpack::update_user_token( $current_user_id, sprintf( '%s.%d', $token, $current_user_id ), $is_master_user ); |
||
| 100 | |||
| 101 | |||
| 102 | if ( $is_master_user ) { |
||
| 103 | Jetpack::state( 'message', 'authorized' ); |
||
| 104 | } else { |
||
| 105 | Jetpack::state( 'message', 'linked' ); |
||
| 106 | // Don't activate anything since we are just connecting a user. |
||
| 107 | break; |
||
| 108 | } |
||
| 109 | |||
| 110 | if ( $active_modules = Jetpack_Options::get_option( 'active_modules' ) ) { |
||
| 111 | Jetpack_Options::delete_option( 'active_modules' ); |
||
| 112 | |||
| 113 | Jetpack::activate_default_modules( 999, 1, $active_modules ); |
||
| 114 | } else { |
||
| 115 | Jetpack::activate_default_modules(); |
||
| 116 | } |
||
| 117 | |||
| 118 | // Sync all registers options and constants |
||
| 119 | /** This action is documented in class.jetpack.php */ |
||
| 120 | do_action( 'jetpack_sync_all_registered_options' ); |
||
| 121 | |||
| 122 | // Start nonce cleaner |
||
| 123 | wp_clear_scheduled_hook( 'jetpack_clean_nonces' ); |
||
| 124 | wp_schedule_event( time(), 'hourly', 'jetpack_clean_nonces' ); |
||
| 125 | } while ( false ); |
||
| 126 | |||
| 127 | if ( wp_validate_redirect( $redirect ) ) { |
||
| 128 | $this->wp_safe_redirect( $redirect ); |
||
| 129 | } else { |
||
| 130 | $this->wp_safe_redirect( Jetpack::admin_url() ); |
||
| 131 | } |
||
| 132 | |||
| 133 | $this->do_exit(); |
||
| 134 | } |
||
| 135 | |||
| 267 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: