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