| 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 |
||
| 390 | public function get_supported_icons() { |
||
| 391 | $social_links_icons = array( |
||
| 392 | array( |
||
| 393 | 'url' => '500px.com', |
||
| 394 | 'icon' => '500px', |
||
| 395 | 'label' => '500px', |
||
| 396 | ), |
||
| 397 | array( |
||
| 398 | 'url' => 'amazon.cn', |
||
| 399 | 'icon' => 'amazon', |
||
| 400 | 'label' => 'Amazon', |
||
| 401 | ), |
||
| 402 | array( |
||
| 403 | 'url' => 'amazon.in', |
||
| 404 | 'icon' => 'amazon', |
||
| 405 | 'label' => 'Amazon', |
||
| 406 | ), |
||
| 407 | array( |
||
| 408 | 'url' => 'amazon.fr', |
||
| 409 | 'icon' => 'amazon', |
||
| 410 | 'label' => 'Amazon', |
||
| 411 | ), |
||
| 412 | array( |
||
| 413 | 'url' => 'amazon.de', |
||
| 414 | 'icon' => 'amazon', |
||
| 415 | 'label' => 'Amazon', |
||
| 416 | ), |
||
| 417 | array( |
||
| 418 | 'url' => 'amazon.it', |
||
| 419 | 'icon' => 'amazon', |
||
| 420 | 'label' => 'Amazon', |
||
| 421 | ), |
||
| 422 | array( |
||
| 423 | 'url' => 'amazon.nl', |
||
| 424 | 'icon' => 'amazon', |
||
| 425 | 'label' => 'Amazon', |
||
| 426 | ), |
||
| 427 | array( |
||
| 428 | 'url' => 'amazon.es', |
||
| 429 | 'icon' => 'amazon', |
||
| 430 | 'label' => 'Amazon', |
||
| 431 | ), |
||
| 432 | array( |
||
| 433 | 'url' => 'amazon.co', |
||
| 434 | 'icon' => 'amazon', |
||
| 435 | 'label' => 'Amazon', |
||
| 436 | ), |
||
| 437 | array( |
||
| 438 | 'url' => 'amazon.ca', |
||
| 439 | 'icon' => 'amazon', |
||
| 440 | 'label' => 'Amazon', |
||
| 441 | ), |
||
| 442 | array( |
||
| 443 | 'url' => 'amazon.com', |
||
| 444 | 'icon' => 'amazon', |
||
| 445 | 'label' => 'Amazon', |
||
| 446 | ), |
||
| 447 | array( |
||
| 448 | 'url' => 'apple.com', |
||
| 449 | 'icon' => 'apple', |
||
| 450 | 'label' => 'Apple', |
||
| 451 | ), |
||
| 452 | array( |
||
| 453 | 'url' => 'itunes.com', |
||
| 454 | 'icon' => 'apple', |
||
| 455 | 'label' => 'iTunes', |
||
| 456 | ), |
||
| 457 | array( |
||
| 458 | 'url' => 'bandcamp.com', |
||
| 459 | 'icon' => 'bandcamp', |
||
| 460 | 'label' => 'Bandcamp', |
||
| 461 | ), |
||
| 462 | array( |
||
| 463 | 'url' => 'behance.net', |
||
| 464 | 'icon' => 'behance', |
||
| 465 | 'label' => 'Behance', |
||
| 466 | ), |
||
| 467 | array( |
||
| 468 | 'url' => 'codepen.io', |
||
| 469 | 'icon' => 'codepen', |
||
| 470 | 'label' => 'CodePen', |
||
| 471 | ), |
||
| 472 | array( |
||
| 473 | 'url' => 'deviantart.com', |
||
| 474 | 'icon' => 'deviantart', |
||
| 475 | 'label' => 'DeviantArt', |
||
| 476 | ), |
||
| 477 | array( |
||
| 478 | 'url' => 'digg.com', |
||
| 479 | 'icon' => 'digg', |
||
| 480 | 'label' => 'Digg', |
||
| 481 | ), |
||
| 482 | array( |
||
| 483 | 'url' => 'dribbble.com', |
||
| 484 | 'icon' => 'dribbble', |
||
| 485 | 'label' => 'Dribbble', |
||
| 486 | ), |
||
| 487 | array( |
||
| 488 | 'url' => 'dropbox.com', |
||
| 489 | 'icon' => 'dropbox', |
||
| 490 | 'label' => 'Dropbox', |
||
| 491 | ), |
||
| 492 | array( |
||
| 493 | 'url' => 'etsy.com', |
||
| 494 | 'icon' => 'etsy', |
||
| 495 | 'label' => 'Etsy', |
||
| 496 | ), |
||
| 497 | array( |
||
| 498 | 'url' => 'facebook.com', |
||
| 499 | 'icon' => 'facebook', |
||
| 500 | 'label' => 'Facebook', |
||
| 501 | ), |
||
| 502 | array( |
||
| 503 | 'url' => '/feed/', |
||
| 504 | 'icon' => 'feed', |
||
| 505 | 'label' => __( 'RSS Feed', 'jetpack' ), |
||
| 506 | ), |
||
| 507 | array( |
||
| 508 | 'url' => 'flickr.com', |
||
| 509 | 'icon' => 'flickr', |
||
| 510 | 'label' => 'Flickr', |
||
| 511 | ), |
||
| 512 | array( |
||
| 513 | 'url' => 'foursquare.com', |
||
| 514 | 'icon' => 'foursquare', |
||
| 515 | 'label' => 'Foursquare', |
||
| 516 | ), |
||
| 517 | array( |
||
| 518 | 'url' => 'goodreads.com', |
||
| 519 | 'icon' => 'goodreads', |
||
| 520 | 'label' => 'Goodreads', |
||
| 521 | ), |
||
| 522 | array( |
||
| 523 | 'url' => 'google.com/+', |
||
| 524 | 'icon' => 'google-plus', |
||
| 525 | 'label' => 'Google +', |
||
| 526 | ), |
||
| 527 | array( |
||
| 528 | 'url' => 'plus.google.com', |
||
| 529 | 'icon' => 'google-plus', |
||
| 530 | 'label' => 'Google +', |
||
| 531 | ), |
||
| 532 | array( |
||
| 533 | 'url' => 'google.com', |
||
| 534 | 'icon' => 'google', |
||
| 535 | 'label' => 'Google', |
||
| 536 | ), |
||
| 537 | array( |
||
| 538 | 'url' => 'github.com', |
||
| 539 | 'icon' => 'github', |
||
| 540 | 'label' => 'GitHub', |
||
| 541 | ), |
||
| 542 | array( |
||
| 543 | 'url' => 'instagram.com', |
||
| 544 | 'icon' => 'instagram', |
||
| 545 | 'label' => 'Instagram', |
||
| 546 | ), |
||
| 547 | array( |
||
| 548 | 'url' => 'linkedin.com', |
||
| 549 | 'icon' => 'linkedin', |
||
| 550 | 'label' => 'LinkedIn', |
||
| 551 | ), |
||
| 552 | array( |
||
| 553 | 'url' => 'mailto:', |
||
| 554 | 'icon' => 'mail', |
||
| 555 | 'label' => __( 'Email', 'jetpack' ), |
||
| 556 | ), |
||
| 557 | array( |
||
| 558 | 'url' => 'meetup.com', |
||
| 559 | 'icon' => 'meetup', |
||
| 560 | 'label' => 'Meetup', |
||
| 561 | ), |
||
| 562 | array( |
||
| 563 | 'url' => 'medium.com', |
||
| 564 | 'icon' => 'medium', |
||
| 565 | 'label' => 'Medium', |
||
| 566 | ), |
||
| 567 | array( |
||
| 568 | 'url' => 'pinterest.com', |
||
| 569 | 'icon' => 'pinterest', |
||
| 570 | 'label' => 'Pinterest', |
||
| 571 | ), |
||
| 572 | array( |
||
| 573 | 'url' => 'getpocket.com', |
||
| 574 | 'icon' => 'pocket', |
||
| 575 | 'label' => 'Pocket', |
||
| 576 | ), |
||
| 577 | array( |
||
| 578 | 'url' => 'reddit.com', |
||
| 579 | 'icon' => 'reddit', |
||
| 580 | 'label' => 'Reddit', |
||
| 581 | ), |
||
| 582 | array( |
||
| 583 | 'url' => 'skype.com', |
||
| 584 | 'icon' => 'skype', |
||
| 585 | 'label' => 'Skype', |
||
| 586 | ), |
||
| 587 | array( |
||
| 588 | 'url' => 'skype:', |
||
| 589 | 'icon' => 'skype', |
||
| 590 | 'label' => 'Skype', |
||
| 591 | ), |
||
| 592 | array( |
||
| 593 | 'url' => 'slideshare.net', |
||
| 594 | 'icon' => 'slideshare', |
||
| 595 | 'label' => 'SlideShare', |
||
| 596 | ), |
||
| 597 | array( |
||
| 598 | 'url' => 'snapchat.com', |
||
| 599 | 'icon' => 'snapchat', |
||
| 600 | 'label' => 'Snapchat', |
||
| 601 | ), |
||
| 602 | array( |
||
| 603 | 'url' => 'soundcloud.com', |
||
| 604 | 'icon' => 'soundcloud', |
||
| 605 | 'label' => 'SoundCloud', |
||
| 606 | ), |
||
| 607 | array( |
||
| 608 | 'url' => 'spotify.com', |
||
| 609 | 'icon' => 'spotify', |
||
| 610 | 'label' => 'Spotify', |
||
| 611 | ), |
||
| 612 | array( |
||
| 613 | 'url' => 'stumbleupon.com', |
||
| 614 | 'icon' => 'stumbleupon', |
||
| 615 | 'label' => 'StumbleUpon', |
||
| 616 | ), |
||
| 617 | array( |
||
| 618 | 'url' => 'tumblr.com', |
||
| 619 | 'icon' => 'tumblr', |
||
| 620 | 'label' => 'Tumblr', |
||
| 621 | ), |
||
| 622 | array( |
||
| 623 | 'url' => 'twitch.tv', |
||
| 624 | 'icon' => 'twitch', |
||
| 625 | 'label' => 'Twitch', |
||
| 626 | ), |
||
| 627 | array( |
||
| 628 | 'url' => 'twitter.com', |
||
| 629 | 'icon' => 'twitter', |
||
| 630 | 'label' => 'Twitter', |
||
| 631 | ), |
||
| 632 | array( |
||
| 633 | 'url' => 'vimeo.com', |
||
| 634 | 'icon' => 'vimeo', |
||
| 635 | 'label' => 'Vimeo', |
||
| 636 | ), |
||
| 637 | array( |
||
| 638 | 'url' => 'vk.com', |
||
| 639 | 'icon' => 'vk', |
||
| 640 | 'label' => 'VK', |
||
| 641 | ), |
||
| 642 | array( |
||
| 643 | 'url' => 'wordpress.com', |
||
| 644 | 'icon' => 'wordpress', |
||
| 645 | 'label' => 'WordPress.com', |
||
| 646 | ), |
||
| 647 | array( |
||
| 648 | 'url' => 'wordpress.org', |
||
| 649 | 'icon' => 'wordpress', |
||
| 650 | 'label' => 'WordPress', |
||
| 651 | ), |
||
| 652 | array( |
||
| 653 | 'url' => 'yelp.com', |
||
| 654 | 'icon' => 'yelp', |
||
| 655 | 'label' => 'Yelp', |
||
| 656 | ), |
||
| 657 | array( |
||
| 658 | 'url' => 'youtube.com', |
||
| 659 | 'icon' => 'youtube', |
||
| 660 | 'label' => 'YouTube', |
||
| 661 | ), |
||
| 662 | ); |
||
| 663 | |||
| 664 | return $social_links_icons; |
||
| 665 | } |
||
| 666 | } // Jetpack_Widget_Social_Icons |
||
| 678 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.