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