Conditions | 19 |
Paths | 18432 |
Total Lines | 231 |
Lines | 12 |
Ratio | 5.19 % |
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 |
||
134 | public static function debug_data() { |
||
135 | $debug_info = array(); |
||
136 | |||
137 | /* Add various important Jetpack options */ |
||
138 | $debug_info['site_id'] = array( |
||
139 | 'label' => 'Jetpack Site ID', |
||
140 | 'value' => \Jetpack_Options::get_option( 'id' ), |
||
141 | 'private' => false, |
||
142 | ); |
||
143 | $debug_info['ssl_cert'] = array( |
||
144 | 'label' => 'Jetpack SSL Verfication Bypass', |
||
145 | 'value' => ( \Jetpack_Options::get_option( 'fallback_no_verify_ssl_certs' ) ) ? 'Yes' : 'No', |
||
146 | 'private' => false, |
||
147 | ); |
||
148 | $debug_info['time_diff'] = array( |
||
149 | 'label' => "Offset between Jetpack server's time and this server's time.", |
||
150 | 'value' => \Jetpack_Options::get_option( 'time_diff' ), |
||
151 | 'private' => false, |
||
152 | ); |
||
153 | $debug_info['version_option'] = array( |
||
154 | 'label' => 'Current Jetpack Version Option', |
||
155 | 'value' => \Jetpack_Options::get_option( 'version' ), |
||
156 | 'private' => false, |
||
157 | ); |
||
158 | $debug_info['old_version'] = array( |
||
159 | 'label' => 'Previous Jetpack Version', |
||
160 | 'value' => \Jetpack_Options::get_option( 'old_version' ), |
||
161 | 'private' => false, |
||
162 | ); |
||
163 | $debug_info['public'] = array( |
||
164 | 'label' => 'Jetpack Site Public', |
||
165 | 'value' => ( \Jetpack_Options::get_option( 'public' ) ) ? 'Public' : 'Private', |
||
166 | 'private' => false, |
||
167 | ); |
||
168 | $debug_info['master_user'] = array( |
||
169 | 'label' => 'Jetpack Master User', |
||
170 | 'value' => self::human_readable_master_user(), |
||
171 | 'private' => false, |
||
172 | ); |
||
173 | |||
174 | /** |
||
175 | * Token information is private, but awareness if there one is set is helpful. |
||
176 | * |
||
177 | * To balance out information vs privacy, we only display and include the "key", |
||
178 | * which is a segment of the token prior to a period within the token and is |
||
179 | * technically not private. |
||
180 | * |
||
181 | * If a token does not contain a period, then it is malformed and we report it as such. |
||
182 | */ |
||
183 | $user_id = get_current_user_id(); |
||
184 | $blog_token = \Jetpack_Data::get_access_token(); |
||
|
|||
185 | $user_token = \Jetpack_Data::get_access_token( $user_id ); |
||
186 | |||
187 | $tokenset = ''; |
||
188 | View Code Duplication | if ( $blog_token ) { |
|
189 | $tokenset = 'Blog '; |
||
190 | $blog_key = substr( $blog_token->secret, 0, strpos( $blog_token->secret, '.' ) ); |
||
191 | // Intentionally not translated since this is helpful when sent to Happiness. |
||
192 | $blog_key = ( $blog_key ) ? $blog_key : 'Potentially Malformed Token.'; |
||
193 | } |
||
194 | View Code Duplication | if ( $user_token ) { |
|
195 | $tokenset .= 'User'; |
||
196 | $user_key = substr( $user_token->secret, 0, strpos( $user_token->secret, '.' ) ); |
||
197 | // Intentionally not translated since this is helpful when sent to Happiness. |
||
198 | $user_key = ( $user_key ) ? $user_key : 'Potentially Malformed Token.'; |
||
199 | } |
||
200 | if ( ! $tokenset ) { |
||
201 | $tokenset = 'None'; |
||
202 | } |
||
203 | |||
204 | $debug_info['current_user'] = array( |
||
205 | 'label' => 'Current User', |
||
206 | 'value' => self::human_readable_user( $user_id ), |
||
207 | 'private' => false, |
||
208 | ); |
||
209 | $debug_info['tokens_set'] = array( |
||
210 | 'label' => 'Tokens defined', |
||
211 | 'value' => $tokenset, |
||
212 | 'private' => false, |
||
213 | ); |
||
214 | $debug_info['blog_token'] = array( |
||
215 | 'label' => 'Blog Public Key', |
||
216 | 'value' => ( $blog_token ) ? $blog_key : 'Not set.', |
||
217 | 'private' => false, |
||
218 | ); |
||
219 | $debug_info['user_token'] = array( |
||
220 | 'label' => 'User Public Key', |
||
221 | 'value' => ( $user_token ) ? $user_key : 'Not set.', |
||
222 | 'private' => false, |
||
223 | ); |
||
224 | |||
225 | /** Jetpack Environmental Information */ |
||
226 | $debug_info['version'] = array( |
||
227 | 'label' => 'Jetpack Version', |
||
228 | 'value' => JETPACK__VERSION, |
||
229 | 'private' => false, |
||
230 | ); |
||
231 | $debug_info['jp_plugin_dir'] = array( |
||
232 | 'label' => 'Jetpack Directory', |
||
233 | 'value' => JETPACK__PLUGIN_DIR, |
||
234 | 'private' => false, |
||
235 | ); |
||
236 | $debug_info['plan'] = array( |
||
237 | 'label' => 'Plan Type', |
||
238 | 'value' => self::what_jetpack_plan(), |
||
239 | 'private' => false, |
||
240 | ); |
||
241 | |||
242 | foreach ( array( |
||
243 | 'HTTP_HOST', |
||
244 | 'SERVER_PORT', |
||
245 | 'HTTPS', |
||
246 | 'GD_PHP_HANDLER', |
||
247 | 'HTTP_AKAMAI_ORIGIN_HOP', |
||
248 | 'HTTP_CF_CONNECTING_IP', |
||
249 | 'HTTP_CLIENT_IP', |
||
250 | 'HTTP_FASTLY_CLIENT_IP', |
||
251 | 'HTTP_FORWARDED', |
||
252 | 'HTTP_FORWARDED_FOR', |
||
253 | 'HTTP_INCAP_CLIENT_IP', |
||
254 | 'HTTP_TRUE_CLIENT_IP', |
||
255 | 'HTTP_X_CLIENTIP', |
||
256 | 'HTTP_X_CLUSTER_CLIENT_IP', |
||
257 | 'HTTP_X_FORWARDED', |
||
258 | 'HTTP_X_FORWARDED_FOR', |
||
259 | 'HTTP_X_IP_TRAIL', |
||
260 | 'HTTP_X_REAL_IP', |
||
261 | 'HTTP_X_VARNISH', |
||
262 | 'REMOTE_ADDR', |
||
263 | ) as $header ) { |
||
264 | if ( isset( $_SERVER[ $header ] ) ) { |
||
265 | $debug_info[ $header ] = array( |
||
266 | 'label' => 'Server Variable ' . $header, |
||
267 | 'value' => ( $_SERVER[ $header ] ) ? $_SERVER[ $header ] : 'false', |
||
268 | 'private' => false, |
||
269 | ); |
||
270 | } |
||
271 | } |
||
272 | |||
273 | $debug_info['protect_header'] = array( |
||
274 | 'label' => 'Trusted IP', |
||
275 | 'value' => wp_json_encode( get_site_option( 'trusted_ip_header' ) ), |
||
276 | 'private' => false, |
||
277 | ); |
||
278 | |||
279 | /** Sync Debug Information */ |
||
280 | $sync_module = Modules::get_module( 'full-sync' ); |
||
281 | if ( $sync_module ) { |
||
282 | $sync_statuses = $sync_module->get_status(); |
||
283 | $human_readable_sync_status = array(); |
||
284 | foreach ( $sync_statuses as $sync_status => $sync_status_value ) { |
||
285 | $human_readable_sync_status[ $sync_status ] = |
||
286 | in_array( $sync_status, array( 'started', 'queue_finished', 'send_started', 'finished' ), true ) |
||
287 | ? gmdate( 'r', $sync_status_value ) : $sync_status_value; |
||
288 | } |
||
289 | $debug_info['full_sync'] = array( |
||
290 | 'label' => 'Full Sync Status', |
||
291 | 'value' => wp_json_encode( $human_readable_sync_status ), |
||
292 | 'private' => false, |
||
293 | ); |
||
294 | } |
||
295 | |||
296 | $queue = Sender::get_instance()->get_sync_queue(); |
||
297 | |||
298 | $debug_info['sync_size'] = array( |
||
299 | 'label' => 'Sync Queue Size', |
||
300 | 'value' => $queue->size(), |
||
301 | 'private' => false, |
||
302 | ); |
||
303 | $debug_info['sync_lag'] = array( |
||
304 | 'label' => 'Sync Queue Lag', |
||
305 | 'value' => self::seconds_to_time( $queue->lag() ), |
||
306 | 'private' => false, |
||
307 | ); |
||
308 | |||
309 | $full_sync_queue = Sender::get_instance()->get_full_sync_queue(); |
||
310 | |||
311 | $debug_info['full_sync_size'] = array( |
||
312 | 'label' => 'Full Sync Queue Size', |
||
313 | 'value' => $full_sync_queue->size(), |
||
314 | 'private' => false, |
||
315 | ); |
||
316 | $debug_info['full_sync_lag'] = array( |
||
317 | 'label' => 'Full Sync Queue Lag', |
||
318 | 'value' => self::seconds_to_time( $full_sync_queue->lag() ), |
||
319 | 'private' => false, |
||
320 | ); |
||
321 | |||
322 | /** |
||
323 | * IDC Information |
||
324 | * |
||
325 | * Must follow sync debug since it depends on sync functionality. |
||
326 | */ |
||
327 | $idc_urls = array( |
||
328 | 'home' => Functions::home_url(), |
||
329 | 'siteurl' => Functions::site_url(), |
||
330 | 'WP_HOME' => Constants::is_defined( 'WP_HOME' ) ? Constants::get_constant( 'WP_HOME' ) : '', |
||
331 | 'WP_SITEURL' => Constants::is_defined( 'WP_SITEURL' ) ? Constants::get_constant( 'WP_SITEURL' ) : '', |
||
332 | ); |
||
333 | |||
334 | $debug_info['idc_urls'] = array( |
||
335 | 'label' => 'IDC URLs', |
||
336 | 'value' => wp_json_encode( $idc_urls ), |
||
337 | 'private' => false, |
||
338 | ); |
||
339 | $debug_info['idc_error_option'] = array( |
||
340 | 'label' => 'IDC Error Option', |
||
341 | 'value' => wp_json_encode( \Jetpack_Options::get_option( 'sync_error_idc' ) ), |
||
342 | 'private' => false, |
||
343 | ); |
||
344 | $debug_info['idc_optin'] = array( |
||
345 | 'label' => 'IDC Opt-in', |
||
346 | 'value' => \Jetpack::sync_idc_optin(), |
||
347 | 'private' => false, |
||
348 | ); |
||
349 | |||
350 | // @todo -- Add testing results? |
||
351 | $cxn_tests = new Tests(); |
||
352 | $debug_info['cxn_tests'] = array( |
||
353 | 'label' => 'Connection Tests', |
||
354 | 'value' => '', |
||
355 | 'private' => false, |
||
356 | ); |
||
357 | if ( $cxn_tests->pass() ) { |
||
358 | $debug_info['cxn_tests']['value'] = 'All Pass.'; |
||
359 | } else { |
||
360 | $debug_info['cxn_tests']['value'] = wp_json_encode( $cxn_tests->list_fails() ); |
||
361 | } |
||
362 | |||
363 | return $debug_info; |
||
364 | } |
||
365 | |||
507 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.