Conditions | 21 |
Paths | 6144 |
Total Lines | 310 |
Lines | 0 |
Ratio | 0 % |
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 |
||
92 | public static function jetpack_debug_display_handler() { |
||
93 | if ( ! current_user_can( 'manage_options' ) ) { |
||
94 | wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'jetpack' ) ); |
||
95 | } |
||
96 | |||
97 | $user_id = get_current_user_id(); |
||
98 | $user_tokens = Jetpack_Options::get_option( 'user_tokens' ); |
||
99 | if ( is_array( $user_tokens ) && array_key_exists( $user_id, $user_tokens ) ) { |
||
100 | $user_token = $user_tokens[ $user_id ]; |
||
101 | } else { |
||
102 | $user_token = '[this user has no token]'; |
||
103 | } |
||
104 | unset( $user_tokens ); |
||
105 | |||
106 | $debug_info = "\r\n"; |
||
107 | foreach ( array( |
||
108 | 'CLIENT_ID' => 'id', |
||
109 | 'BLOG_TOKEN' => 'blog_token', |
||
110 | 'MASTER_USER' => 'master_user', |
||
111 | 'CERT' => 'fallback_no_verify_ssl_certs', |
||
112 | 'TIME_DIFF' => 'time_diff', |
||
113 | 'VERSION' => 'version', |
||
114 | 'OLD_VERSION' => 'old_version', |
||
115 | 'PUBLIC' => 'public', |
||
116 | ) as $label => $option_name ) { |
||
117 | $debug_info .= "\r\n" . esc_html( $label . ': ' . Jetpack_Options::get_option( $option_name ) ); |
||
118 | } |
||
119 | |||
120 | $debug_info .= "\r\n" . esc_html( 'USER_ID: ' . $user_id ); |
||
121 | $debug_info .= "\r\n" . esc_html( 'USER_TOKEN: ' . $user_token ); |
||
122 | $debug_info .= "\r\n" . esc_html( 'PHP_VERSION: ' . PHP_VERSION ); |
||
123 | $debug_info .= "\r\n" . esc_html( 'WORDPRESS_VERSION: ' . $GLOBALS['wp_version'] ); |
||
124 | $debug_info .= "\r\n" . esc_html( 'JETPACK__VERSION: ' . JETPACK__VERSION ); |
||
125 | $debug_info .= "\r\n" . esc_html( 'JETPACK__PLUGIN_DIR: ' . JETPACK__PLUGIN_DIR ); |
||
126 | $debug_info .= "\r\n" . esc_html( 'SITE_URL: ' . site_url() ); |
||
127 | $debug_info .= "\r\n" . esc_html( 'HOME_URL: ' . home_url() ); |
||
128 | $debug_info .= "\r\n" . esc_html( 'PLAN: ' . self::what_jetpack_plan() ); |
||
129 | |||
130 | $debug_info .= "\r\n"; |
||
131 | |||
132 | $debug_info .= "\r\n" . '-- SYNC Status -- '; |
||
133 | require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-modules.php'; |
||
134 | $sync_module = Jetpack_Sync_Modules::get_module( 'full-sync' ); |
||
135 | if ( $sync_module ) { |
||
136 | $sync_statuses = $sync_module->get_status(); |
||
137 | $human_readable_sync_status = array(); |
||
138 | foreach ( $sync_statuses as $sync_status => $sync_status_value ) { |
||
139 | $human_readable_sync_status[ $sync_status ] = |
||
140 | in_array( $sync_status, array( 'started', 'queue_finished', 'send_started', 'finished' ), true ) |
||
141 | ? date( 'r', $sync_status_value ) : $sync_status_value; |
||
142 | } |
||
143 | /* translators: A string reporting status. Example: "started" */ |
||
144 | $debug_info .= "\r\n" . sprintf( esc_html__( 'Jetpack Sync Full Status: `%1$s`', 'jetpack' ), print_r( $human_readable_sync_status, 1 ) ); //phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r |
||
145 | } |
||
146 | |||
147 | require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-sender.php'; |
||
148 | |||
149 | $queue = Jetpack_Sync_Sender::get_instance()->get_sync_queue(); |
||
150 | |||
151 | /* translators: The number of items waiting to be synced. */ |
||
152 | $debug_info .= "\r\n" . sprintf( esc_html__( 'Sync Queue size: %1$s', 'jetpack' ), $queue->size() ); |
||
153 | /* translators: Human-readable time since the oldest item in the sync queue. */ |
||
154 | $debug_info .= "\r\n" . sprintf( esc_html__( 'Sync Queue lag: %1$s', 'jetpack' ), self::seconds_to_time( $queue->lag() ) ); |
||
155 | |||
156 | $full_sync_queue = Jetpack_Sync_Sender::get_instance()->get_full_sync_queue(); |
||
157 | |||
158 | /* translators: The number of items waiting to be synced. */ |
||
159 | $debug_info .= "\r\n" . sprintf( esc_html__( 'Full Sync Queue size: %1$s', 'jetpack' ), $full_sync_queue->size() ); |
||
160 | /* translators: Human-readable time since the oldest item in the sync queue. */ |
||
161 | $debug_info .= "\r\n" . sprintf( esc_html__( 'Full Sync Queue lag: %1$s', 'jetpack' ), self::seconds_to_time( $full_sync_queue->lag() ) ); |
||
162 | |||
163 | require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-functions.php'; |
||
164 | $idc_urls = array( |
||
165 | 'home' => Jetpack_Sync_Functions::home_url(), |
||
166 | 'siteurl' => Jetpack_Sync_Functions::site_url(), |
||
167 | 'WP_HOME' => Jetpack_Constants::is_defined( 'WP_HOME' ) ? Jetpack_Constants::get_constant( 'WP_HOME' ) : '', |
||
168 | 'WP_SITEURL' => Jetpack_Constants::is_defined( 'WP_SITEURL' ) ? Jetpack_Constants::get_constant( 'WP_SITEURL' ) : '', |
||
169 | ); |
||
170 | /* translators: List of URLs. */ |
||
171 | $debug_info .= "\r\n" . esc_html( sprintf( 'Sync IDC URLs: %s', wp_json_encode( $idc_urls ) ) ); |
||
172 | /* translators: String of a current option. */ |
||
173 | $debug_info .= "\r\n" . esc_html( sprintf( 'Sync error IDC option: %s', wp_json_encode( Jetpack_Options::get_option( 'sync_error_idc' ) ) ) ); |
||
174 | /* translators: String of a current option. */ |
||
175 | $debug_info .= "\r\n" . esc_html( sprintf( 'Sync IDC Optin: %s', (string) Jetpack::sync_idc_optin() ) ); |
||
176 | |||
177 | $debug_info .= "\r\n"; |
||
178 | |||
179 | foreach ( array( |
||
180 | 'HTTP_HOST', |
||
181 | 'SERVER_PORT', |
||
182 | 'HTTPS', |
||
183 | 'GD_PHP_HANDLER', |
||
184 | 'HTTP_AKAMAI_ORIGIN_HOP', |
||
185 | 'HTTP_CF_CONNECTING_IP', |
||
186 | 'HTTP_CLIENT_IP', |
||
187 | 'HTTP_FASTLY_CLIENT_IP', |
||
188 | 'HTTP_FORWARDED', |
||
189 | 'HTTP_FORWARDED_FOR', |
||
190 | 'HTTP_INCAP_CLIENT_IP', |
||
191 | 'HTTP_TRUE_CLIENT_IP', |
||
192 | 'HTTP_X_CLIENTIP', |
||
193 | 'HTTP_X_CLUSTER_CLIENT_IP', |
||
194 | 'HTTP_X_FORWARDED', |
||
195 | 'HTTP_X_FORWARDED_FOR', |
||
196 | 'HTTP_X_IP_TRAIL', |
||
197 | 'HTTP_X_REAL_IP', |
||
198 | 'HTTP_X_VARNISH', |
||
199 | 'REMOTE_ADDR', |
||
200 | ) as $header ) { |
||
201 | if ( isset( $_SERVER[ $header ] ) ) { |
||
202 | $debug_info .= "\r\n" . esc_html( $header . ': ' . $_SERVER[ $header ] ); |
||
203 | } |
||
204 | } |
||
205 | |||
206 | $debug_info .= "\r\n" . esc_html( 'PROTECT_TRUSTED_HEADER: ' . wp_json_encode( get_site_option( 'trusted_ip_header' ) ) ); |
||
207 | |||
208 | $debug_info .= "\r\n\r\nTEST RESULTS:\r\n\r\n"; |
||
209 | |||
210 | $cxntests = new Jetpack_Cxn_Tests(); |
||
211 | ?> |
||
212 | <div class="wrap"> |
||
213 | <h2><?php esc_html_e( 'Debugging Center', 'jetpack' ); ?></h2> |
||
214 | <h3><?php esc_html_e( "Testing your site's compatibility with Jetpack...", 'jetpack' ); ?></h3> |
||
215 | <div class="jetpack-debug-test-container"> |
||
216 | <?php |
||
217 | if ( $cxntests->pass() ) { |
||
218 | echo '<div class="jetpack-tests-succeed">' . esc_html__( 'Your Jetpack setup looks a-okay!', 'jetpack' ) . '</div>'; |
||
219 | $debug_info .= "All tests passed.\r\n"; |
||
220 | $debug_info .= print_r( $cxntests->raw_results(), true ); //phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r |
||
221 | } else { |
||
222 | $failures = $cxntests->list_fails(); |
||
223 | foreach ( $failures as $fail ) { |
||
|
|||
224 | echo '<div class="jetpack-test-error">'; |
||
225 | echo '<p><a class="jetpack-test-heading" href="#">' . esc_html( $fail['message'] ); |
||
226 | echo '<span class="noticon noticon-collapse"></span></a></p>'; |
||
227 | echo '<p class="jetpack-test-details">' . esc_html( $fail['resolution'] ) . '</p>'; |
||
228 | echo '</div>'; |
||
229 | |||
230 | $debug_info .= "FAILED TESTS!\r\n"; |
||
231 | $debug_info .= $fail['name'] . ': ' . $fail['message'] . "\r\n"; |
||
232 | $debug_info .= print_r( $cxntests->raw_results(), true ); //phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r |
||
233 | } |
||
234 | } |
||
235 | ?> |
||
236 | </div> |
||
237 | <div class="entry-content"> |
||
238 | <h3><?php esc_html_e( 'Trouble with Jetpack?', 'jetpack' ); ?></h3> |
||
239 | <h4><?php esc_html_e( 'It may be caused by one of these issues, which you can diagnose yourself:', 'jetpack' ); ?></h4> |
||
240 | <ol> |
||
241 | <li><b><em> |
||
242 | <?php |
||
243 | esc_html_e( 'A known issue.', 'jetpack' ); |
||
244 | ?> |
||
245 | </em></b> |
||
246 | <?php |
||
247 | echo sprintf( |
||
248 | wp_kses( |
||
249 | /* translators: URLs to Jetpack support pages. */ |
||
250 | __( 'Some themes and plugins have <a href="%1$s" target="_blank">known conflicts</a> with Jetpack – check the <a href="%2$s" target="_blank">list</a>. (You can also browse the <a href="%3$s" target="_blank">Jetpack support pages</a> or <a href="%4$s" target="_blank">Jetpack support forum</a> to see if others have experienced and solved the problem.)', 'jetpack' ), |
||
251 | array( |
||
252 | 'a' => array( |
||
253 | 'href' => array(), |
||
254 | 'target' => array(), |
||
255 | ), |
||
256 | ) |
||
257 | ), |
||
258 | 'http://jetpack.com/support/getting-started-with-jetpack/known-issues/', |
||
259 | 'http://jetpack.com/support/getting-started-with-jetpack/known-issues/', |
||
260 | 'http://jetpack.com/support/', |
||
261 | 'https://wordpress.org/support/plugin/jetpack' |
||
262 | ); |
||
263 | ?> |
||
264 | </li> |
||
265 | <li><b><em><?php esc_html_e( 'An incompatible plugin.', 'jetpack' ); ?></em></b> <?php esc_html_e( "Find out by disabling all plugins except Jetpack. If the problem persists, it's not a plugin issue. If the problem is solved, turn your plugins on one by one until the problem pops up again – there's the culprit! Let us know, and we'll try to help.", 'jetpack' ); ?></li> |
||
266 | <li> |
||
267 | <b><em><?php esc_html_e( 'A theme conflict.', 'jetpack' ); ?></em></b> |
||
268 | <?php |
||
269 | $default_theme = wp_get_theme( WP_DEFAULT_THEME ); |
||
270 | |||
271 | if ( $default_theme->exists() ) { |
||
272 | /* translators: %s is the name of a theme */ |
||
273 | echo esc_html( sprintf( __( "If your problem isn't known or caused by a plugin, try activating %s (the default WordPress theme).", 'jetpack' ), $default_theme->get( 'Name' ) ) ); |
||
274 | } else { |
||
275 | esc_html_e( "If your problem isn't known or caused by a plugin, try activating the default WordPress theme.", 'jetpack' ); |
||
276 | } |
||
277 | ?> |
||
278 | <?php esc_html_e( "If this solves the problem, something in your theme is probably broken – let the theme's author know.", 'jetpack' ); ?> |
||
279 | </li> |
||
280 | <li><b><em><?php esc_html_e( 'A problem with your XMLRPC file.', 'jetpack' ); ?></em></b> |
||
281 | <?php |
||
282 | echo sprintf( |
||
283 | wp_kses( |
||
284 | /* translators: The URL to the site's xmlrpc.php file. */ |
||
285 | __( 'Load your <a href="%s">XMLRPC file</a>. It should say “XML-RPC server accepts POST requests only.” on a line by itself.', 'jetpack' ), |
||
286 | array( 'a' => array( 'href' => array() ) ) |
||
287 | ), |
||
288 | esc_attr( site_url( 'xmlrpc.php' ) ) |
||
289 | ); |
||
290 | ?> |
||
291 | <ul> |
||
292 | <li>- <?php esc_html_e( "If it's not by itself, a theme or plugin is displaying extra characters. Try steps 2 and 3.", 'jetpack' ); ?></li> |
||
293 | <li>- <?php esc_html_e( 'If you get a 404 message, contact your web host. Their security may block XMLRPC.', 'jetpack' ); ?></li> |
||
294 | </ul> |
||
295 | </li> |
||
296 | <?php if ( current_user_can( 'jetpack_disconnect' ) && Jetpack::is_active() ) : ?> |
||
297 | <li> |
||
298 | <strong><em><?php esc_html_e( 'A connection problem with WordPress.com.', 'jetpack' ); ?></em></strong> |
||
299 | <?php |
||
300 | echo sprintf( |
||
301 | wp_kses( |
||
302 | /* translators: URL to disconnect and reconnect Jetpack. */ |
||
303 | __( 'Jetpack works by connecting to WordPress.com for a lot of features. Sometimes, when the connection gets messed up, you need to disconnect and reconnect to get things working properly. <a href="%s">Disconnect from WordPress.com</a>', 'jetpack' ), |
||
304 | array( |
||
305 | 'a' => array( |
||
306 | 'href' => array(), |
||
307 | 'class' => array(), |
||
308 | ), |
||
309 | ) |
||
310 | ), |
||
311 | esc_attr( |
||
312 | wp_nonce_url( |
||
313 | Jetpack::admin_url( |
||
314 | array( |
||
315 | 'page' => 'jetpack-debugger', |
||
316 | 'disconnect' => true, |
||
317 | ) |
||
318 | ), |
||
319 | 'jp_disconnect', |
||
320 | 'nonce' |
||
321 | ) |
||
322 | ) |
||
323 | ); |
||
324 | ?> |
||
325 | </li> |
||
326 | <?php endif; ?> |
||
327 | </ol> |
||
328 | <h4><?php esc_html_e( 'Still having trouble?', 'jetpack' ); ?></h4> |
||
329 | <p><b><em><?php esc_html_e( 'Ask us for help!', 'jetpack' ); ?></em></b> |
||
330 | <?php |
||
331 | echo sprintf( |
||
332 | wp_kses( |
||
333 | /* translators: URL for Jetpack support. */ |
||
334 | __( '<a href="%s">Contact our Happiness team</a>. When you do, please include the full debug information below.', 'jetpack' ), |
||
335 | array( 'a' => array( 'href' => array() ) ) |
||
336 | ), |
||
337 | 'https://jetpack.com/contact-support/' |
||
338 | ); |
||
339 | ?> |
||
340 | </p> |
||
341 | <hr /> |
||
342 | <?php if ( Jetpack::is_active() ) : ?> |
||
343 | <div id="connected-user-details"> |
||
344 | <h3><?php esc_html_e( 'More details about your Jetpack settings', 'jetpack' ); ?></h3> |
||
345 | <p> |
||
346 | <?php |
||
347 | printf( |
||
348 | wp_kses( |
||
349 | /* translators: %s is an e-mail address */ |
||
350 | __( 'The primary connection is owned by <strong>%s</strong>\'s WordPress.com account.', 'jetpack' ), |
||
351 | array( 'strong' => array() ) |
||
352 | ), |
||
353 | esc_html( Jetpack::get_master_user_email() ) |
||
354 | ); |
||
355 | ?> |
||
356 | </p> |
||
357 | </div> |
||
358 | <?php else : ?> |
||
359 | <div id="dev-mode-details"> |
||
360 | <p> |
||
361 | <?php |
||
362 | printf( |
||
363 | wp_kses( |
||
364 | /* translators: Link to a Jetpack support page. */ |
||
365 | __( 'Would you like to use Jetpack on your local development site? You can do so thanks to <a href="%s">Jetpack\'s development mode</a>.', 'jetpack' ), |
||
366 | array( 'a' => array( 'href' => array() ) ) |
||
367 | ), |
||
368 | 'https://jetpack.com/support/development-mode/' |
||
369 | ); |
||
370 | ?> |
||
371 | </p> |
||
372 | </div> |
||
373 | <?php endif; ?> |
||
374 | <?php |
||
375 | if ( |
||
376 | current_user_can( 'jetpack_manage_modules' ) |
||
377 | && ( Jetpack::is_development_mode() || Jetpack::is_active() ) |
||
378 | ) { |
||
379 | printf( |
||
380 | wp_kses( |
||
381 | '<p><a href="%1$s">%2$s</a></p>', |
||
382 | array( |
||
383 | 'a' => array( 'href' => array() ), |
||
384 | 'p' => array(), |
||
385 | ) |
||
386 | ), |
||
387 | esc_attr( Jetpack::admin_url( 'page=jetpack_modules' ) ), |
||
388 | esc_html__( 'Access the full list of Jetpack modules available on your site.', 'jetpack' ) |
||
389 | ); |
||
390 | } |
||
391 | ?> |
||
392 | </div> |
||
393 | <hr /> |
||
394 | <div id="toggle_debug_info"><?php esc_html_e( 'Advanced Debug Results', 'jetpack' ); ?></div> |
||
395 | <div id="debug_info_div"> |
||
396 | <h4><?php esc_html_e( 'Debug Info', 'jetpack' ); ?></h4> |
||
397 | <div id="debug_info"><pre><?php echo esc_html( $debug_info ); ?></pre></div> |
||
398 | </div> |
||
399 | </div> |
||
400 | <?php |
||
401 | } |
||
402 | |||
531 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.