Conditions | 6 |
Paths | 4 |
Total Lines | 238 |
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 |
||
342 | public function form( $instance ) { |
||
343 | $defaults = array( |
||
344 | 'title' => esc_html__( 'Follow me on Twitter', 'jetpack' ), |
||
345 | 'width' => '220', |
||
346 | 'height' => '200', |
||
347 | 'type' => 'profile', |
||
348 | 'widget-id' => '', |
||
349 | 'border-color' => '#e8e8e8', |
||
350 | 'theme' => 'light', |
||
351 | 'chrome' => array(), |
||
352 | 'tweet-limit' => 1, |
||
353 | 'tweet-display' => 'dynamic', |
||
354 | ); |
||
355 | |||
356 | $instance = wp_parse_args( (array) $instance, $defaults ); |
||
|
|||
357 | |||
358 | if ( 'widget-id' === $instance['type'] ) { |
||
359 | $instance['widget-id'] = ''; |
||
360 | } |
||
361 | |||
362 | $instance['type'] = 'profile'; |
||
363 | |||
364 | /** |
||
365 | * Set the tweet-display option to 'fixed' if height is empty and tweet-limit set |
||
366 | * to ensure backwards compatibility with pre-existing widgets. |
||
367 | */ |
||
368 | if ( empty( $instance['height'] ) && isset( $instance['tweet-limit'] ) ) { |
||
369 | $instance['tweet-display'] = 'fixed'; |
||
370 | } |
||
371 | ?> |
||
372 | |||
373 | <p class="jetpack-twitter-timeline-widget-id-container"> |
||
374 | <label for="<?php echo esc_attr( $this->get_field_id( 'widget-id' ) ); ?>"> |
||
375 | <?php esc_html_e( 'Twitter username:', 'jetpack' ); ?> |
||
376 | <?php |
||
377 | echo wp_kses( |
||
378 | $this->get_docs_link( '#twitter-username' ), |
||
379 | array( |
||
380 | 'a' => array( |
||
381 | 'href' => array(), |
||
382 | 'rel' => array(), |
||
383 | 'target' => array(), |
||
384 | 'class' => array(), |
||
385 | ), |
||
386 | ) |
||
387 | ); |
||
388 | ?> |
||
389 | </label> |
||
390 | <input |
||
391 | class="widefat" |
||
392 | id="<?php echo esc_attr( $this->get_field_id( 'widget-id' ) ); ?>" |
||
393 | name="<?php echo esc_attr( $this->get_field_name( 'widget-id' ) ); ?>" |
||
394 | type="text" |
||
395 | value="<?php echo esc_attr( $instance['widget-id'] ); ?>" |
||
396 | /> |
||
397 | </p> |
||
398 | |||
399 | <p> |
||
400 | <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"> |
||
401 | <?php esc_html_e( 'Title:', 'jetpack' ); ?> |
||
402 | </label> |
||
403 | <input |
||
404 | class="widefat" |
||
405 | id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" |
||
406 | name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" |
||
407 | type="text" |
||
408 | value="<?php echo esc_attr( $instance['title'] ); ?>" |
||
409 | /> |
||
410 | </p> |
||
411 | |||
412 | <p> |
||
413 | <label> |
||
414 | <strong><?php esc_html_e( 'Number of tweets shown:', 'jetpack' ); ?></strong> |
||
415 | </label> |
||
416 | <ul> |
||
417 | <li> |
||
418 | <label> |
||
419 | <input |
||
420 | id="<?php echo esc_attr( $this->get_field_id( 'tweet-display' ) ); ?>-dynamic" |
||
421 | name="<?php echo esc_attr( $this->get_field_name( 'tweet-display' ) ); ?>" |
||
422 | type="radio" |
||
423 | class="jetpack-twitter-timeline-widget-tweet-display-radio" |
||
424 | value="dynamic" |
||
425 | <?php checked( 'dynamic', $instance['tweet-display'] ); ?> |
||
426 | /> |
||
427 | <?php esc_html_e( 'Dynamic', 'jetpack' ); ?> |
||
428 | </label> |
||
429 | </li> |
||
430 | <li> |
||
431 | <label> |
||
432 | <input |
||
433 | id="<?php echo esc_attr( $this->get_field_id( 'tweet-display' ) ); ?>-fixed" |
||
434 | name="<?php echo esc_attr( $this->get_field_name( 'tweet-display' ) ); ?>" |
||
435 | type="radio" |
||
436 | class="jetpack-twitter-timeline-widget-tweet-display-radio" |
||
437 | value="fixed" |
||
438 | <?php checked( 'fixed', $instance['tweet-display'] ); ?> |
||
439 | /> |
||
440 | <?php esc_html_e( 'Fixed', 'jetpack' ); ?> |
||
441 | </label> |
||
442 | </li> |
||
443 | </ul> |
||
444 | </p> |
||
445 | |||
446 | <p class="jetpack-twitter-timeline-widget-height-container" <?php echo ( 'fixed' === $instance['tweet-display'] ) ? ' style="display:none;"' : ''; ?>> |
||
447 | <label for="<?php echo esc_attr( $this->get_field_id( 'height' ) ); ?>"> |
||
448 | <?php esc_html_e( 'Height (in pixels; at least 200):', 'jetpack' ); ?> |
||
449 | </label> |
||
450 | <input |
||
451 | class="widefat" |
||
452 | id="<?php echo esc_attr( $this->get_field_id( 'height' ) ); ?>" |
||
453 | name="<?php echo esc_attr( $this->get_field_name( 'height' ) ); ?>" |
||
454 | type="number" min="200" |
||
455 | value="<?php echo esc_attr( $instance['height'] ); ?>" |
||
456 | /> |
||
457 | </p> |
||
458 | |||
459 | <p class="jetpack-twitter-timeline-widget-tweet-limit-container" <?php echo ( 'dynamic' === $instance['tweet-display'] ) ? ' style="display:none;"' : ''; ?>> |
||
460 | <label for="<?php echo esc_attr( $this->get_field_id( 'tweet-limit' ) ); ?>"> |
||
461 | <?php esc_html_e( 'Number of tweets in the timeline (1 to 20):', 'jetpack' ); ?> |
||
462 | </label> |
||
463 | <input |
||
464 | class="widefat" |
||
465 | id="<?php echo esc_attr( $this->get_field_id( 'tweet-limit' ) ); ?>" |
||
466 | name="<?php echo esc_attr( $this->get_field_name( 'tweet-limit' ) ); ?>" |
||
467 | type="number" min="1" max="20" |
||
468 | value="<?php echo esc_attr( $instance['tweet-limit'] ); ?>" |
||
469 | /> |
||
470 | </p> |
||
471 | |||
472 | <p> |
||
473 | <label for="<?php echo esc_attr( $this->get_field_id( 'width' ) ); ?>"> |
||
474 | <?php esc_html_e( 'Maximum width (in pixels; 220 to 1200):', 'jetpack' ); ?> |
||
475 | </label> |
||
476 | <input |
||
477 | class="widefat" |
||
478 | id="<?php echo esc_attr( $this->get_field_id( 'width' ) ); ?>" |
||
479 | name="<?php echo esc_attr( $this->get_field_name( 'width' ) ); ?>" |
||
480 | type="number" min="220" max="1200" |
||
481 | value="<?php echo esc_attr( $instance['width'] ); ?>" |
||
482 | /> |
||
483 | </p> |
||
484 | |||
485 | <p> |
||
486 | <label for="<?php echo esc_attr( $this->get_field_id( 'chrome-noheader' ) ); ?>"> |
||
487 | <strong><?php esc_html_e( 'Layout options:', 'jetpack' ); ?></strong> |
||
488 | </label> |
||
489 | </p> |
||
490 | <p> |
||
491 | <input |
||
492 | type="checkbox" |
||
493 | <?php checked( false, in_array( 'noheader', $instance['chrome'], true ) ); ?> |
||
494 | id="<?php echo esc_attr( $this->get_field_id( 'chrome-noheader' ) ); ?>" |
||
495 | name="<?php echo esc_attr( $this->get_field_name( 'chrome' ) ); ?>[]" |
||
496 | value="noheader" |
||
497 | /> |
||
498 | <label for="<?php echo esc_attr( $this->get_field_id( 'chrome-noheader' ) ); ?>"> |
||
499 | <?php esc_html_e( 'Show header', 'jetpack' ); ?> |
||
500 | </label> |
||
501 | <br /> |
||
502 | <input |
||
503 | type="checkbox" |
||
504 | <?php checked( false, in_array( 'nofooter', $instance['chrome'], true ) ); ?> |
||
505 | id="<?php echo esc_attr( $this->get_field_id( 'chrome-nofooter' ) ); ?>" |
||
506 | name="<?php echo esc_attr( $this->get_field_name( 'chrome' ) ); ?>[]" |
||
507 | value="nofooter" |
||
508 | /> |
||
509 | <label for="<?php echo esc_attr( $this->get_field_id( 'chrome-nofooter' ) ); ?>"> |
||
510 | <?php esc_html_e( 'Show footer', 'jetpack' ); ?> |
||
511 | </label> |
||
512 | <br /> |
||
513 | <input |
||
514 | type="checkbox" |
||
515 | <?php checked( false, in_array( 'noborders', $instance['chrome'], true ) ); ?> |
||
516 | id="<?php echo esc_attr( $this->get_field_id( 'chrome-noborders' ) ); ?>" |
||
517 | name="<?php echo esc_attr( $this->get_field_name( 'chrome' ) ); ?>[]" |
||
518 | value="noborders" |
||
519 | /> |
||
520 | <label for="<?php echo esc_attr( $this->get_field_id( 'chrome-noborders' ) ); ?>"> |
||
521 | <?php esc_html_e( 'Show borders', 'jetpack' ); ?> |
||
522 | </label> |
||
523 | <br /> |
||
524 | <input |
||
525 | type="checkbox" |
||
526 | <?php checked( false, in_array( 'noscrollbar', $instance['chrome'], true ) ); ?> |
||
527 | id="<?php echo esc_attr( $this->get_field_id( 'chrome-noscrollbar' ) ); ?>" |
||
528 | name="<?php echo esc_attr( $this->get_field_name( 'chrome' ) ); ?>[]" |
||
529 | value="noscrollbar" |
||
530 | <?php disabled( 'fixed', $instance['tweet-display'] ); ?> |
||
531 | /> |
||
532 | <label for="<?php echo esc_attr( $this->get_field_id( 'chrome-noscrollbar' ) ); ?>"> |
||
533 | <?php esc_html_e( 'Show scrollbar', 'jetpack' ); ?> |
||
534 | </label> |
||
535 | <br /> |
||
536 | <input |
||
537 | type="checkbox" |
||
538 | <?php checked( in_array( 'transparent', $instance['chrome'], true ) ); ?> |
||
539 | id="<?php echo esc_attr( $this->get_field_id( 'chrome-transparent' ) ); ?>" |
||
540 | name="<?php echo esc_attr( $this->get_field_name( 'chrome' ) ); ?>[]" |
||
541 | value="transparent" |
||
542 | /> |
||
543 | <label for="<?php echo esc_attr( $this->get_field_id( 'chrome-transparent' ) ); ?>"> |
||
544 | <?php esc_html_e( 'Transparent background', 'jetpack' ); ?> |
||
545 | </label> |
||
546 | </p> |
||
547 | |||
548 | <p> |
||
549 | <label for="<?php echo esc_attr( $this->get_field_id( 'border-color' ) ); ?>"> |
||
550 | <?php esc_html_e( 'Border color (in hex format):', 'jetpack' ); ?> |
||
551 | </label> |
||
552 | <input |
||
553 | class="widefat" |
||
554 | id="<?php echo esc_attr( $this->get_field_id( 'border-color' ) ); ?>" |
||
555 | name="<?php echo esc_attr( $this->get_field_name( 'border-color' ) ); ?>" |
||
556 | type="text" |
||
557 | value="<?php echo esc_attr( $instance['border-color'] ); ?>" |
||
558 | /> |
||
559 | </p> |
||
560 | |||
561 | <p> |
||
562 | <label for="<?php echo esc_attr( $this->get_field_id( 'theme' ) ); ?>"> |
||
563 | <?php esc_html_e( 'Color scheme:', 'jetpack' ); ?> |
||
564 | </label> |
||
565 | <select |
||
566 | name="<?php echo esc_attr( $this->get_field_name( 'theme' ) ); ?>" |
||
567 | id="<?php echo esc_attr( $this->get_field_id( 'theme' ) ); ?>" |
||
568 | class="widefat" |
||
569 | > |
||
570 | <option value="light"<?php selected( $instance['theme'], 'light' ); ?>> |
||
571 | <?php esc_html_e( 'Light', 'jetpack' ); ?> |
||
572 | </option> |
||
573 | <option value="dark"<?php selected( $instance['theme'], 'dark' ); ?>> |
||
574 | <?php esc_html_e( 'Dark', 'jetpack' ); ?> |
||
575 | </option> |
||
576 | </select> |
||
577 | </p> |
||
578 | <?php |
||
579 | } |
||
580 | } |
||
581 |
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: