Conditions | 1 |
Paths | 1 |
Total Lines | 276 |
Code Lines | 219 |
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 |
||
379 | public function get_supported_icons() { |
||
380 | $social_links_icons = array( |
||
381 | array( |
||
382 | 'url' => '500px.com', |
||
383 | 'icon' => '500px', |
||
384 | 'label' => '500px', |
||
385 | ), |
||
386 | array( |
||
387 | 'url' => 'amazon.cn', |
||
388 | 'icon' => 'amazon', |
||
389 | 'label' => 'Amazon', |
||
390 | ), |
||
391 | array( |
||
392 | 'url' => 'amazon.in', |
||
393 | 'icon' => 'amazon', |
||
394 | 'label' => 'Amazon', |
||
395 | ), |
||
396 | array( |
||
397 | 'url' => 'amazon.fr', |
||
398 | 'icon' => 'amazon', |
||
399 | 'label' => 'Amazon', |
||
400 | ), |
||
401 | array( |
||
402 | 'url' => 'amazon.de', |
||
403 | 'icon' => 'amazon', |
||
404 | 'label' => 'Amazon', |
||
405 | ), |
||
406 | array( |
||
407 | 'url' => 'amazon.it', |
||
408 | 'icon' => 'amazon', |
||
409 | 'label' => 'Amazon', |
||
410 | ), |
||
411 | array( |
||
412 | 'url' => 'amazon.nl', |
||
413 | 'icon' => 'amazon', |
||
414 | 'label' => 'Amazon', |
||
415 | ), |
||
416 | array( |
||
417 | 'url' => 'amazon.es', |
||
418 | 'icon' => 'amazon', |
||
419 | 'label' => 'Amazon', |
||
420 | ), |
||
421 | array( |
||
422 | 'url' => 'amazon.co', |
||
423 | 'icon' => 'amazon', |
||
424 | 'label' => 'Amazon', |
||
425 | ), |
||
426 | array( |
||
427 | 'url' => 'amazon.ca', |
||
428 | 'icon' => 'amazon', |
||
429 | 'label' => 'Amazon', |
||
430 | ), |
||
431 | array( |
||
432 | 'url' => 'amazon.com', |
||
433 | 'icon' => 'amazon', |
||
434 | 'label' => 'Amazon', |
||
435 | ), |
||
436 | array( |
||
437 | 'url' => 'apple.com', |
||
438 | 'icon' => 'apple', |
||
439 | 'label' => 'Apple', |
||
440 | ), |
||
441 | array( |
||
442 | 'url' => 'itunes.com', |
||
443 | 'icon' => 'apple', |
||
444 | 'label' => 'iTunes', |
||
445 | ), |
||
446 | array( |
||
447 | 'url' => 'bandcamp.com', |
||
448 | 'icon' => 'bandcamp', |
||
449 | 'label' => 'Bandcamp', |
||
450 | ), |
||
451 | array( |
||
452 | 'url' => 'behance.net', |
||
453 | 'icon' => 'behance', |
||
454 | 'label' => 'Behance', |
||
455 | ), |
||
456 | array( |
||
457 | 'url' => 'codepen.io', |
||
458 | 'icon' => 'codepen', |
||
459 | 'label' => 'CodePen', |
||
460 | ), |
||
461 | array( |
||
462 | 'url' => 'deviantart.com', |
||
463 | 'icon' => 'deviantart', |
||
464 | 'label' => 'DeviantArt', |
||
465 | ), |
||
466 | array( |
||
467 | 'url' => 'digg.com', |
||
468 | 'icon' => 'digg', |
||
469 | 'label' => 'Digg', |
||
470 | ), |
||
471 | array( |
||
472 | 'url' => 'dribbble.com', |
||
473 | 'icon' => 'dribbble', |
||
474 | 'label' => 'Dribbble', |
||
475 | ), |
||
476 | array( |
||
477 | 'url' => 'dropbox.com', |
||
478 | 'icon' => 'dropbox', |
||
479 | 'label' => 'Dropbox', |
||
480 | ), |
||
481 | array( |
||
482 | 'url' => 'etsy.com', |
||
483 | 'icon' => 'etsy', |
||
484 | 'label' => 'Etsy', |
||
485 | ), |
||
486 | array( |
||
487 | 'url' => 'facebook.com', |
||
488 | 'icon' => 'facebook', |
||
489 | 'label' => 'Facebook', |
||
490 | ), |
||
491 | array( |
||
492 | 'url' => '/feed/', |
||
493 | 'icon' => 'feed', |
||
494 | 'label' => __( 'RSS Feed', 'jetpack' ), |
||
495 | ), |
||
496 | array( |
||
497 | 'url' => 'flickr.com', |
||
498 | 'icon' => 'flickr', |
||
499 | 'label' => 'Flickr', |
||
500 | ), |
||
501 | array( |
||
502 | 'url' => 'foursquare.com', |
||
503 | 'icon' => 'foursquare', |
||
504 | 'label' => 'Foursquare', |
||
505 | ), |
||
506 | array( |
||
507 | 'url' => 'goodreads.com', |
||
508 | 'icon' => 'goodreads', |
||
509 | 'label' => 'Goodreads', |
||
510 | ), |
||
511 | array( |
||
512 | 'url' => 'google.com/+', |
||
513 | 'icon' => 'google-plus', |
||
514 | 'label' => 'Google +', |
||
515 | ), |
||
516 | array( |
||
517 | 'url' => 'plus.google.com', |
||
518 | 'icon' => 'google-plus', |
||
519 | 'label' => 'Google +', |
||
520 | ), |
||
521 | array( |
||
522 | 'url' => 'google.com', |
||
523 | 'icon' => 'google', |
||
524 | 'label' => 'Google', |
||
525 | ), |
||
526 | array( |
||
527 | 'url' => 'github.com', |
||
528 | 'icon' => 'github', |
||
529 | 'label' => 'GitHub', |
||
530 | ), |
||
531 | array( |
||
532 | 'url' => 'instagram.com', |
||
533 | 'icon' => 'instagram', |
||
534 | 'label' => 'Instagram', |
||
535 | ), |
||
536 | array( |
||
537 | 'url' => 'linkedin.com', |
||
538 | 'icon' => 'linkedin', |
||
539 | 'label' => 'LinkedIn', |
||
540 | ), |
||
541 | array( |
||
542 | 'url' => 'mailto:', |
||
543 | 'icon' => 'mail', |
||
544 | 'label' => __( 'Email', 'jetpack' ), |
||
545 | ), |
||
546 | array( |
||
547 | 'url' => 'meetup.com', |
||
548 | 'icon' => 'meetup', |
||
549 | 'label' => 'Meetup', |
||
550 | ), |
||
551 | array( |
||
552 | 'url' => 'medium.com', |
||
553 | 'icon' => 'medium', |
||
554 | 'label' => 'Medium', |
||
555 | ), |
||
556 | array( |
||
557 | 'url' => 'pinterest.com', |
||
558 | 'icon' => 'pinterest', |
||
559 | 'label' => 'Pinterest', |
||
560 | ), |
||
561 | array( |
||
562 | 'url' => 'getpocket.com', |
||
563 | 'icon' => 'pocket', |
||
564 | 'label' => 'Pocket', |
||
565 | ), |
||
566 | array( |
||
567 | 'url' => 'reddit.com', |
||
568 | 'icon' => 'reddit', |
||
569 | 'label' => 'Reddit', |
||
570 | ), |
||
571 | array( |
||
572 | 'url' => 'skype.com', |
||
573 | 'icon' => 'skype', |
||
574 | 'label' => 'Skype', |
||
575 | ), |
||
576 | array( |
||
577 | 'url' => 'skype:', |
||
578 | 'icon' => 'skype', |
||
579 | 'label' => 'Skype', |
||
580 | ), |
||
581 | array( |
||
582 | 'url' => 'slideshare.net', |
||
583 | 'icon' => 'slideshare', |
||
584 | 'label' => 'SlideShare', |
||
585 | ), |
||
586 | array( |
||
587 | 'url' => 'snapchat.com', |
||
588 | 'icon' => 'snapchat', |
||
589 | 'label' => 'Snapchat', |
||
590 | ), |
||
591 | array( |
||
592 | 'url' => 'soundcloud.com', |
||
593 | 'icon' => 'soundcloud', |
||
594 | 'label' => 'SoundCloud', |
||
595 | ), |
||
596 | array( |
||
597 | 'url' => 'spotify.com', |
||
598 | 'icon' => 'spotify', |
||
599 | 'label' => 'Spotify', |
||
600 | ), |
||
601 | array( |
||
602 | 'url' => 'stumbleupon.com', |
||
603 | 'icon' => 'stumbleupon', |
||
604 | 'label' => 'StumbleUpon', |
||
605 | ), |
||
606 | array( |
||
607 | 'url' => 'tumblr.com', |
||
608 | 'icon' => 'tumblr', |
||
609 | 'label' => 'Tumblr', |
||
610 | ), |
||
611 | array( |
||
612 | 'url' => 'twitch.tv', |
||
613 | 'icon' => 'twitch', |
||
614 | 'label' => 'Twitch', |
||
615 | ), |
||
616 | array( |
||
617 | 'url' => 'twitter.com', |
||
618 | 'icon' => 'twitter', |
||
619 | 'label' => 'Twitter', |
||
620 | ), |
||
621 | array( |
||
622 | 'url' => 'vimeo.com', |
||
623 | 'icon' => 'vimeo', |
||
624 | 'label' => 'Vimeo', |
||
625 | ), |
||
626 | array( |
||
627 | 'url' => 'vk.com', |
||
628 | 'icon' => 'vk', |
||
629 | 'label' => 'VK', |
||
630 | ), |
||
631 | array( |
||
632 | 'url' => 'wordpress.com', |
||
633 | 'icon' => 'wordpress', |
||
634 | 'label' => 'WordPress.com', |
||
635 | ), |
||
636 | array( |
||
637 | 'url' => 'wordpress.org', |
||
638 | 'icon' => 'wordpress', |
||
639 | 'label' => 'WordPress', |
||
640 | ), |
||
641 | array( |
||
642 | 'url' => 'yelp.com', |
||
643 | 'icon' => 'yelp', |
||
644 | 'label' => 'Yelp', |
||
645 | ), |
||
646 | array( |
||
647 | 'url' => 'youtube.com', |
||
648 | 'icon' => 'youtube', |
||
649 | 'label' => 'YouTube', |
||
650 | ), |
||
651 | ); |
||
652 | |||
653 | return $social_links_icons; |
||
654 | } |
||
655 | } // Jetpack_Widget_Social_Icons |
||
667 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: