| Conditions | 2 |
| Paths | 2 |
| Total Lines | 176 |
| 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 |
||
| 311 | public function form( $instance ) { |
||
| 312 | $defaults = array( |
||
| 313 | 'title' => esc_html__( 'Follow me on Twitter', 'jetpack' ), |
||
| 314 | 'width' => '', |
||
| 315 | 'height' => '400', |
||
| 316 | 'type' => 'profile', |
||
| 317 | 'widget-id' => '', |
||
| 318 | 'border-color' => '#e8e8e8', |
||
| 319 | 'theme' => 'light', |
||
| 320 | 'chrome' => array(), |
||
| 321 | 'tweet-limit' => null, |
||
| 322 | ); |
||
| 323 | |||
| 324 | $instance = wp_parse_args( (array) $instance, $defaults ); |
||
| 325 | |||
| 326 | if ( 'widget-id' === $instance['type'] ) { |
||
| 327 | $instance['widget-id'] = ''; |
||
| 328 | } |
||
| 329 | |||
| 330 | $instance['type'] = 'profile'; |
||
| 331 | ?> |
||
| 332 | |||
| 333 | <p> |
||
| 334 | <label for="<?php echo $this->get_field_id( 'title' ); ?>"> |
||
| 335 | <?php esc_html_e( 'Title:', 'jetpack' ); ?> |
||
| 336 | </label> |
||
| 337 | <input |
||
| 338 | class="widefat" |
||
| 339 | id="<?php echo $this->get_field_id( 'title' ); ?>" |
||
| 340 | name="<?php echo $this->get_field_name( 'title' ); ?>" |
||
| 341 | type="text" |
||
| 342 | value="<?php echo esc_attr( $instance['title'] ); ?>" |
||
| 343 | /> |
||
| 344 | </p> |
||
| 345 | |||
| 346 | <p> |
||
| 347 | <label for="<?php echo $this->get_field_id( 'width' ); ?>"> |
||
| 348 | <?php esc_html_e( 'Maximum Width (px; 220 to 1200):', 'jetpack' ); ?> |
||
| 349 | </label> |
||
| 350 | <input |
||
| 351 | class="widefat" |
||
| 352 | id="<?php echo $this->get_field_id( 'width' ); ?>" |
||
| 353 | name="<?php echo $this->get_field_name( 'width' ); ?>" |
||
| 354 | type="number" min="220" max="1200" |
||
| 355 | value="<?php echo esc_attr( $instance['width'] ); ?>" |
||
| 356 | /> |
||
| 357 | </p> |
||
| 358 | |||
| 359 | <p> |
||
| 360 | <label for="<?php echo $this->get_field_id( 'height' ); ?>"> |
||
| 361 | <?php esc_html_e( 'Height (px; at least 200):', 'jetpack' ); ?> |
||
| 362 | </label> |
||
| 363 | <input |
||
| 364 | class="widefat" |
||
| 365 | id="<?php echo $this->get_field_id( 'height' ); ?>" |
||
| 366 | name="<?php echo $this->get_field_name( 'height' ); ?>" |
||
| 367 | type="number" min="200" |
||
| 368 | value="<?php echo esc_attr( $instance['height'] ); ?>" |
||
| 369 | /> |
||
| 370 | </p> |
||
| 371 | |||
| 372 | <p> |
||
| 373 | <label for="<?php echo $this->get_field_id( 'tweet-limit' ); ?>"> |
||
| 374 | <?php esc_html_e( '# of Tweets Shown (1 to 20):', 'jetpack' ); ?> |
||
| 375 | </label> |
||
| 376 | <input |
||
| 377 | class="widefat" |
||
| 378 | id="<?php echo $this->get_field_id( 'tweet-limit' ); ?>" |
||
| 379 | name="<?php echo $this->get_field_name( 'tweet-limit' ); ?>" |
||
| 380 | type="number" min="1" max="20" |
||
| 381 | value="<?php echo esc_attr( $instance['tweet-limit'] ); ?>" |
||
| 382 | /> |
||
| 383 | </p> |
||
| 384 | |||
| 385 | <p class="jetpack-twitter-timeline-widget-id-container"> |
||
| 386 | <label for="<?php echo $this->get_field_id( 'widget-id' ); ?>"> |
||
| 387 | <?php esc_html_e( 'Twitter Username:', 'jetpack' ); ?> |
||
| 388 | <?php echo $this->get_docs_link( '#twitter-username' ); ?> |
||
| 389 | </label> |
||
| 390 | <input |
||
| 391 | class="widefat" |
||
| 392 | id="<?php echo $this->get_field_id( 'widget-id' ); ?>" |
||
| 393 | name="<?php echo $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 $this->get_field_id( 'chrome-noheader' ); ?>"> |
||
| 401 | <?php esc_html_e( 'Layout Options:', 'jetpack' ); ?> |
||
| 402 | </label> |
||
| 403 | <br /> |
||
| 404 | <input |
||
| 405 | type="checkbox"<?php checked( in_array( 'noheader', $instance['chrome'] ) ); ?> |
||
| 406 | id="<?php echo $this->get_field_id( 'chrome-noheader' ); ?>" |
||
| 407 | name="<?php echo $this->get_field_name( 'chrome' ); ?>[]" |
||
| 408 | value="noheader" |
||
| 409 | /> |
||
| 410 | <label for="<?php echo $this->get_field_id( 'chrome-noheader' ); ?>"> |
||
| 411 | <?php esc_html_e( 'No Header', 'jetpack' ); ?> |
||
| 412 | </label> |
||
| 413 | <br /> |
||
| 414 | <input |
||
| 415 | type="checkbox"<?php checked( in_array( 'nofooter', $instance['chrome'] ) ); ?> |
||
| 416 | id="<?php echo $this->get_field_id( 'chrome-nofooter' ); ?>" |
||
| 417 | name="<?php echo $this->get_field_name( 'chrome' ); ?>[]" |
||
| 418 | value="nofooter" |
||
| 419 | /> |
||
| 420 | <label for="<?php echo $this->get_field_id( 'chrome-nofooter' ); ?>"> |
||
| 421 | <?php esc_html_e( 'No Footer', 'jetpack' ); ?> |
||
| 422 | </label> |
||
| 423 | <br /> |
||
| 424 | <input |
||
| 425 | type="checkbox"<?php checked( in_array( 'noborders', $instance['chrome'] ) ); ?> |
||
| 426 | id="<?php echo $this->get_field_id( 'chrome-noborders' ); ?>" |
||
| 427 | name="<?php echo $this->get_field_name( 'chrome' ); ?>[]" |
||
| 428 | value="noborders" |
||
| 429 | /> |
||
| 430 | <label for="<?php echo $this->get_field_id( 'chrome-noborders' ); ?>"> |
||
| 431 | <?php esc_html_e( 'No Borders', 'jetpack' ); ?> |
||
| 432 | </label> |
||
| 433 | <br /> |
||
| 434 | <input |
||
| 435 | type="checkbox"<?php checked( in_array( 'noscrollbar', $instance['chrome'] ) ); ?> |
||
| 436 | id="<?php echo $this->get_field_id( 'chrome-noscrollbar' ); ?>" |
||
| 437 | name="<?php echo $this->get_field_name( 'chrome' ); ?>[]" |
||
| 438 | value="noscrollbar" |
||
| 439 | /> |
||
| 440 | <label for="<?php echo $this->get_field_id( 'chrome-noscrollbar' ); ?>"> |
||
| 441 | <?php esc_html_e( 'No Scrollbar', 'jetpack' ); ?> |
||
| 442 | </label> |
||
| 443 | <br /> |
||
| 444 | <input |
||
| 445 | type="checkbox"<?php checked( in_array( 'transparent', $instance['chrome'] ) ); ?> |
||
| 446 | id="<?php echo $this->get_field_id( 'chrome-transparent' ); ?>" |
||
| 447 | name="<?php echo $this->get_field_name( 'chrome' ); ?>[]" |
||
| 448 | value="transparent" |
||
| 449 | /> |
||
| 450 | <label for="<?php echo $this->get_field_id( 'chrome-transparent' ); ?>"> |
||
| 451 | <?php esc_html_e( 'Transparent Background', 'jetpack' ); ?> |
||
| 452 | </label> |
||
| 453 | </p> |
||
| 454 | |||
| 455 | <p> |
||
| 456 | <label for="<?php echo $this->get_field_id( 'border-color' ); ?>"> |
||
| 457 | <?php _e( 'Border Color (hex):', 'jetpack' ); ?> |
||
| 458 | </label> |
||
| 459 | <input |
||
| 460 | class="widefat" |
||
| 461 | id="<?php echo $this->get_field_id( 'border-color' ); ?>" |
||
| 462 | name="<?php echo $this->get_field_name( 'border-color' ); ?>" |
||
| 463 | type="text" |
||
| 464 | value="<?php echo esc_attr( $instance['border-color'] ); ?>" |
||
| 465 | /> |
||
| 466 | </p> |
||
| 467 | |||
| 468 | <p> |
||
| 469 | <label for="<?php echo $this->get_field_id( 'theme' ); ?>"> |
||
| 470 | <?php _e( 'Timeline Theme:', 'jetpack' ); ?> |
||
| 471 | </label> |
||
| 472 | <select |
||
| 473 | name="<?php echo $this->get_field_name( 'theme' ); ?>" |
||
| 474 | id="<?php echo $this->get_field_id( 'theme' ); ?>" |
||
| 475 | class="widefat" |
||
| 476 | > |
||
| 477 | <option value="light"<?php selected( $instance['theme'], 'light' ); ?>> |
||
| 478 | <?php esc_html_e( 'Light', 'jetpack' ); ?> |
||
| 479 | </option> |
||
| 480 | <option value="dark"<?php selected( $instance['theme'], 'dark' ); ?>> |
||
| 481 | <?php esc_html_e( 'Dark', 'jetpack' ); ?> |
||
| 482 | </option> |
||
| 483 | </select> |
||
| 484 | </p> |
||
| 485 | <?php |
||
| 486 | } |
||
| 487 | } |
||
| 488 |