Conditions | 2 |
Paths | 19 |
Total Lines | 91 |
Lines | 11 |
Ratio | 12.09 % |
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 |
||
60 | function admin_page_load() { |
||
61 | if ( isset( $_GET['action'] ) ) { |
||
62 | if ( isset( $_GET['service'] ) ) { |
||
63 | $service_name = $_GET['service']; |
||
64 | } |
||
65 | |||
66 | switch ( $_GET['action'] ) { |
||
67 | case 'error': |
||
68 | add_action( 'pre_admin_screen_sharing', array( $this, 'display_connection_error' ), 9 ); |
||
69 | break; |
||
70 | |||
71 | case 'request': |
||
72 | check_admin_referer( 'keyring-request', 'kr_nonce' ); |
||
73 | check_admin_referer( "keyring-request-$service_name", 'nonce' ); |
||
74 | |||
75 | $verification = Jetpack::generate_secrets( 'publicize' ); |
||
76 | if ( ! $verification ) { |
||
77 | $url = Jetpack::admin_url( 'jetpack#/settings' ); |
||
78 | wp_die( sprintf( __( "Jetpack is not connected. Please connect Jetpack by visiting <a href='%s'>Settings</a>.", 'jetpack' ), $url ) ); |
||
79 | |||
80 | } |
||
81 | $stats_options = get_option( 'stats_options' ); |
||
82 | $wpcom_blog_id = Jetpack_Options::get_option( 'id' ); |
||
83 | $wpcom_blog_id = ! empty( $wpcom_blog_id ) ? $wpcom_blog_id : $stats_options['blog_id']; |
||
84 | |||
85 | $user = wp_get_current_user(); |
||
86 | $redirect = $this->api_url( $service_name, urlencode_deep( array( |
||
87 | 'action' => 'request', |
||
88 | 'redirect_uri' => add_query_arg( array( 'action' => 'done' ), menu_page_url( 'sharing', false ) ), |
||
89 | 'for' => 'publicize', |
||
90 | // required flag that says this connection is intended for publicize |
||
91 | 'siteurl' => site_url(), |
||
92 | 'state' => $user->ID, |
||
93 | 'blog_id' => $wpcom_blog_id, |
||
94 | 'secret_1' => $verification['secret_1'], |
||
95 | 'secret_2' => $verification['secret_2'], |
||
96 | 'eol' => $verification['exp'], |
||
97 | ) ) ); |
||
98 | wp_redirect( $redirect ); |
||
99 | exit; |
||
100 | break; |
||
101 | |||
102 | case 'completed': |
||
103 | Jetpack::load_xml_rpc_client(); |
||
104 | $xml = new Jetpack_IXR_Client(); |
||
105 | $xml->query( 'jetpack.fetchPublicizeConnections' ); |
||
106 | |||
107 | if ( ! $xml->isError() ) { |
||
108 | $response = $xml->getResponse(); |
||
109 | Jetpack_Options::update_option( 'publicize_connections', $response ); |
||
110 | } |
||
111 | |||
112 | break; |
||
113 | |||
114 | case 'delete': |
||
115 | $id = $_GET['id']; |
||
116 | |||
117 | check_admin_referer( 'keyring-request', 'kr_nonce' ); |
||
118 | check_admin_referer( "keyring-request-$service_name", 'nonce' ); |
||
119 | |||
120 | $this->disconnect( $service_name, $id ); |
||
121 | |||
122 | add_action( 'admin_notices', array( $this, 'display_disconnected' ) ); |
||
123 | break; |
||
124 | } |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * Remove a Publicize connection |
||
129 | */ |
||
130 | View Code Duplication | function disconnect( $service_name, $connection_id, $_blog_id = false, $_user_id = false, $force_delete = false ) { |
|
131 | Jetpack::load_xml_rpc_client(); |
||
132 | $xml = new Jetpack_IXR_Client(); |
||
133 | $xml->query( 'jetpack.deletePublicizeConnection', $connection_id ); |
||
134 | |||
135 | if ( ! $xml->isError() ) { |
||
136 | Jetpack_Options::update_option( 'publicize_connections', $xml->getResponse() ); |
||
137 | } else { |
||
138 | return false; |
||
139 | } |
||
140 | } |
||
141 | |||
142 | // Do we really need `admin_styles`? With the new admin UI, it's breaking some bits. |
||
143 | // Errors encountered on WordPress.com's end are passed back as a code |
||
144 | /* |
||
145 | if ( isset( $_GET['action'] ) && 'error' == $_GET['action'] ) { |
||
146 | // Load Jetpack's styles to handle the box |
||
147 | Jetpack::init()->admin_styles(); |
||
148 | } |
||
149 | */ |
||
150 | } |
||
151 | |||
227 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: