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