Conditions | 6 |
Paths | 3 |
Total Lines | 225 |
Code Lines | 127 |
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 |
||
276 | public function form( $instance ) { |
||
277 | $defaults = array( |
||
278 | 'title' => esc_html__( 'Follow me on Twitter', 'jetpack' ), |
||
279 | 'width' => '', |
||
280 | 'height' => '400', |
||
281 | 'widget-id' => '', |
||
282 | 'link-color' => '#f96e5b', |
||
283 | 'border-color' => '#e8e8e8', |
||
284 | 'theme' => 'light', |
||
285 | 'chrome' => array(), |
||
286 | 'tweet-limit' => null, |
||
287 | ); |
||
288 | |||
289 | $instance = wp_parse_args( (array) $instance, $defaults ); |
||
290 | |||
291 | if ( empty( $instance['type'] ) ) { |
||
292 | // Decide the correct widget type. If this is a pre-existing |
||
293 | // widget with a numeric widget ID, then the type should be |
||
294 | // 'widget-id', otherwise it should be 'profile'. |
||
295 | if ( ! empty( $instance['widget-id'] ) && is_numeric( $instance['widget-id'] ) ) { |
||
296 | $instance['type'] = 'widget-id'; |
||
297 | } else { |
||
298 | $instance['type'] = 'profile'; |
||
299 | } |
||
300 | } |
||
301 | ?> |
||
302 | |||
303 | <p> |
||
304 | <label for="<?php echo $this->get_field_id( 'title' ); ?>"> |
||
305 | <?php esc_html_e( 'Title:', 'jetpack' ); ?> |
||
306 | </label> |
||
307 | <input |
||
308 | class="widefat" |
||
309 | id="<?php echo $this->get_field_id( 'title' ); ?>" |
||
310 | name="<?php echo $this->get_field_name( 'title' ); ?>" |
||
311 | type="text" |
||
312 | value="<?php echo esc_attr( $instance['title'] ); ?>" |
||
313 | /> |
||
314 | </p> |
||
315 | |||
316 | <p> |
||
317 | <label for="<?php echo $this->get_field_id( 'width' ); ?>"> |
||
318 | <?php esc_html_e( 'Maximum Width (px; 220 to 1200):', 'jetpack' ); ?> |
||
319 | </label> |
||
320 | <input |
||
321 | class="widefat" |
||
322 | id="<?php echo $this->get_field_id( 'width' ); ?>" |
||
323 | name="<?php echo $this->get_field_name( 'width' ); ?>" |
||
324 | type="number" min="220" max="1200" |
||
325 | value="<?php echo esc_attr( $instance['width'] ); ?>" |
||
326 | /> |
||
327 | </p> |
||
328 | |||
329 | <p> |
||
330 | <label for="<?php echo $this->get_field_id( 'height' ); ?>"> |
||
331 | <?php esc_html_e( 'Height (px; at least 200):', 'jetpack' ); ?> |
||
332 | </label> |
||
333 | <input |
||
334 | class="widefat" |
||
335 | id="<?php echo $this->get_field_id( 'height' ); ?>" |
||
336 | name="<?php echo $this->get_field_name( 'height' ); ?>" |
||
337 | type="number" min="200" |
||
338 | value="<?php echo esc_attr( $instance['height'] ); ?>" |
||
339 | /> |
||
340 | </p> |
||
341 | |||
342 | <p> |
||
343 | <label for="<?php echo $this->get_field_id( 'tweet-limit' ); ?>"> |
||
344 | <?php esc_html_e( '# of Tweets Shown (1 to 20):', 'jetpack' ); ?> |
||
345 | </label> |
||
346 | <input |
||
347 | class="widefat" |
||
348 | id="<?php echo $this->get_field_id( 'tweet-limit' ); ?>" |
||
349 | name="<?php echo $this->get_field_name( 'tweet-limit' ); ?>" |
||
350 | type="number" min="1" max="20" |
||
351 | value="<?php echo esc_attr( $instance['tweet-limit'] ); ?>" |
||
352 | /> |
||
353 | </p> |
||
354 | |||
355 | <p class="jetpack-twitter-timeline-widget-type-container"> |
||
356 | <label for="<?php echo $this->get_field_id( 'type' ); ?>"> |
||
357 | <?php esc_html_e( 'Widget Type:', 'jetpack' ); ?> |
||
358 | <?php echo $this->get_docs_link( '#widget-type' ); ?> |
||
359 | </label> |
||
360 | <select |
||
361 | name="<?php echo $this->get_field_name( 'type' ); ?>" |
||
362 | id="<?php echo $this->get_field_id( 'type' ); ?>" |
||
363 | class="jetpack-twitter-timeline-widget-type widefat" |
||
364 | > |
||
365 | <option value="profile"<?php selected( $instance['type'], 'profile' ); ?>> |
||
366 | <?php esc_html_e( 'Profile', 'jetpack' ); ?> |
||
367 | </option> |
||
368 | <option value="widget-id"<?php selected( $instance['type'], 'widget-id' ); ?>> |
||
369 | <?php esc_html_e( 'Widget ID', 'jetpack' ); ?> |
||
370 | </option> |
||
371 | </select> |
||
372 | </p> |
||
373 | |||
374 | <p class="jetpack-twitter-timeline-widget-id-container"> |
||
375 | <label |
||
376 | for="<?php echo $this->get_field_id( 'widget-id' ); ?>" |
||
377 | data-widget-type="widget-id" |
||
378 | <?php echo ( 'widget-id' === $instance['type'] ? '' : 'style="display: none;"' ); ?> |
||
379 | > |
||
380 | <?php esc_html_e( 'Widget ID:', 'jetpack' ); ?> |
||
381 | <?php echo $this->get_docs_link( '#widget-id' ); ?> |
||
382 | </label> |
||
383 | <label |
||
384 | for="<?php echo $this->get_field_id( 'widget-id' ); ?>" |
||
385 | data-widget-type="profile" |
||
386 | <?php echo ( 'profile' === $instance['type'] ? '' : 'style="display: none;"' ); ?> |
||
387 | > |
||
388 | <?php esc_html_e( 'Twitter Username:', 'jetpack' ); ?> |
||
389 | <?php echo $this->get_docs_link( '#twitter-username' ); ?> |
||
390 | </label> |
||
391 | <input |
||
392 | class="widefat" |
||
393 | id="<?php echo $this->get_field_id( 'widget-id' ); ?>" |
||
394 | name="<?php echo $this->get_field_name( 'widget-id' ); ?>" |
||
395 | type="text" |
||
396 | value="<?php echo esc_attr( $instance['widget-id'] ); ?>" |
||
397 | /> |
||
398 | </p> |
||
399 | |||
400 | <p> |
||
401 | <label for="<?php echo $this->get_field_id( 'chrome-noheader' ); ?>"> |
||
402 | <?php esc_html_e( 'Layout Options:', 'jetpack' ); ?> |
||
403 | </label> |
||
404 | <br /> |
||
405 | <input |
||
406 | type="checkbox"<?php checked( in_array( 'noheader', $instance['chrome'] ) ); ?> |
||
407 | id="<?php echo $this->get_field_id( 'chrome-noheader' ); ?>" |
||
408 | name="<?php echo $this->get_field_name( 'chrome' ); ?>[]" |
||
409 | value="noheader" |
||
410 | /> |
||
411 | <label for="<?php echo $this->get_field_id( 'chrome-noheader' ); ?>"> |
||
412 | <?php esc_html_e( 'No Header', 'jetpack' ); ?> |
||
413 | </label> |
||
414 | <br /> |
||
415 | <input |
||
416 | type="checkbox"<?php checked( in_array( 'nofooter', $instance['chrome'] ) ); ?> |
||
417 | id="<?php echo $this->get_field_id( 'chrome-nofooter' ); ?>" |
||
418 | name="<?php echo $this->get_field_name( 'chrome' ); ?>[]" |
||
419 | value="nofooter" |
||
420 | /> |
||
421 | <label for="<?php echo $this->get_field_id( 'chrome-nofooter' ); ?>"> |
||
422 | <?php esc_html_e( 'No Footer', 'jetpack' ); ?> |
||
423 | </label> |
||
424 | <br /> |
||
425 | <input |
||
426 | type="checkbox"<?php checked( in_array( 'noborders', $instance['chrome'] ) ); ?> |
||
427 | id="<?php echo $this->get_field_id( 'chrome-noborders' ); ?>" |
||
428 | name="<?php echo $this->get_field_name( 'chrome' ); ?>[]" |
||
429 | value="noborders" |
||
430 | /> |
||
431 | <label for="<?php echo $this->get_field_id( 'chrome-noborders' ); ?>"> |
||
432 | <?php esc_html_e( 'No Borders', 'jetpack' ); ?> |
||
433 | </label> |
||
434 | <br /> |
||
435 | <input |
||
436 | type="checkbox"<?php checked( in_array( 'noscrollbar', $instance['chrome'] ) ); ?> |
||
437 | id="<?php echo $this->get_field_id( 'chrome-noscrollbar' ); ?>" |
||
438 | name="<?php echo $this->get_field_name( 'chrome' ); ?>[]" |
||
439 | value="noscrollbar" |
||
440 | /> |
||
441 | <label for="<?php echo $this->get_field_id( 'chrome-noscrollbar' ); ?>"> |
||
442 | <?php esc_html_e( 'No Scrollbar', 'jetpack' ); ?> |
||
443 | </label> |
||
444 | <br /> |
||
445 | <input |
||
446 | type="checkbox"<?php checked( in_array( 'transparent', $instance['chrome'] ) ); ?> |
||
447 | id="<?php echo $this->get_field_id( 'chrome-transparent' ); ?>" |
||
448 | name="<?php echo $this->get_field_name( 'chrome' ); ?>[]" |
||
449 | value="transparent" |
||
450 | /> |
||
451 | <label for="<?php echo $this->get_field_id( 'chrome-transparent' ); ?>"> |
||
452 | <?php esc_html_e( 'Transparent Background', 'jetpack' ); ?> |
||
453 | </label> |
||
454 | </p> |
||
455 | |||
456 | <p> |
||
457 | <label for="<?php echo $this->get_field_id( 'link-color' ); ?>"> |
||
458 | <?php _e( 'Link Color (hex):', 'jetpack' ); ?> |
||
459 | </label> |
||
460 | <input |
||
461 | class="widefat" |
||
462 | id="<?php echo $this->get_field_id( 'link-color' ); ?>" |
||
463 | name="<?php echo $this->get_field_name( 'link-color' ); ?>" |
||
464 | type="text" |
||
465 | value="<?php echo esc_attr( $instance['link-color'] ); ?>" |
||
466 | /> |
||
467 | </p> |
||
468 | |||
469 | <p> |
||
470 | <label for="<?php echo $this->get_field_id( 'border-color' ); ?>"> |
||
471 | <?php _e( 'Border Color (hex):', 'jetpack' ); ?> |
||
472 | </label> |
||
473 | <input |
||
474 | class="widefat" |
||
475 | id="<?php echo $this->get_field_id( 'border-color' ); ?>" |
||
476 | name="<?php echo $this->get_field_name( 'border-color' ); ?>" |
||
477 | type="text" |
||
478 | value="<?php echo esc_attr( $instance['border-color'] ); ?>" |
||
479 | /> |
||
480 | </p> |
||
481 | |||
482 | <p> |
||
483 | <label for="<?php echo $this->get_field_id( 'theme' ); ?>"> |
||
484 | <?php _e( 'Timeline Theme:', 'jetpack' ); ?> |
||
485 | </label> |
||
486 | <select |
||
487 | name="<?php echo $this->get_field_name( 'theme' ); ?>" |
||
488 | id="<?php echo $this->get_field_id( 'theme' ); ?>" |
||
489 | class="widefat" |
||
490 | > |
||
491 | <option value="light"<?php selected( $instance['theme'], 'light' ); ?>> |
||
492 | <?php esc_html_e( 'Light', 'jetpack' ); ?> |
||
493 | </option> |
||
494 | <option value="dark"<?php selected( $instance['theme'], 'dark' ); ?>> |
||
495 | <?php esc_html_e( 'Dark', 'jetpack' ); ?> |
||
496 | </option> |
||
497 | </select> |
||
498 | </p> |
||
499 | <?php |
||
500 | } |
||
501 | } |
||
502 |