Conditions | 3 |
Paths | 2 |
Total Lines | 319 |
Code Lines | 222 |
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 |
||
489 | public function getCallInfoProvider() |
||
490 | { |
||
491 | $aliases = array( |
||
492 | array('kint', 'dump'), |
||
493 | 'd', |
||
494 | 's', |
||
495 | ); |
||
496 | |||
497 | $basetrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); |
||
498 | $basetrace[0]['file'] = __FILE__; |
||
499 | $basetrace[0]['line'] = __LINE__; |
||
500 | $dumpframe = array( |
||
501 | 'class' => 'Kint', |
||
502 | 'function' => 'dump', |
||
503 | ); |
||
504 | |||
505 | $data['empty trace'] = array( |
||
506 | 'aliases' => $aliases, |
||
507 | 'trace' => array( |
||
508 | ), |
||
509 | 'param_count' => 1234, |
||
510 | 'expect' => array( |
||
511 | 'params' => null, |
||
512 | 'modifiers' => array(), |
||
513 | 'callee' => null, |
||
514 | 'caller' => null, |
||
515 | 'trace' => array(), |
||
516 | ), |
||
517 | ); |
||
518 | |||
519 | $data['full trace'] = array( |
||
520 | 'aliases' => $aliases, |
||
521 | 'trace' => array_merge( |
||
522 | $basetrace, |
||
523 | array( |
||
524 | $dumpframe + array( |
||
525 | 'file' => TestClass::DUMP_FILE, |
||
526 | 'line' => TestClass::DUMP_LINE, |
||
527 | ), |
||
528 | ), |
||
529 | array( |
||
530 | array( |
||
531 | 'function' => 'usort', |
||
532 | ), |
||
533 | ), |
||
534 | $basetrace |
||
535 | ), |
||
536 | 'param_count' => 1234, |
||
537 | 'expect' => array( |
||
538 | 'params' => null, |
||
539 | 'modifiers' => array(), |
||
540 | 'callee' => $dumpframe + array( |
||
541 | 'file' => TestClass::DUMP_FILE, |
||
542 | 'line' => TestClass::DUMP_LINE, |
||
543 | ), |
||
544 | 'caller' => array( |
||
545 | 'function' => 'usort', |
||
546 | ), |
||
547 | 'trace' => array_merge( |
||
548 | array( |
||
549 | $dumpframe + array( |
||
550 | 'file' => TestClass::DUMP_FILE, |
||
551 | 'line' => TestClass::DUMP_LINE, |
||
552 | ), |
||
553 | ), |
||
554 | $basetrace |
||
555 | ), |
||
556 | ), |
||
557 | ); |
||
558 | |||
559 | $data['unmatching trace'] = $data['full trace']; |
||
560 | $data['unmatching trace']['aliases'] = array(); |
||
561 | $data['unmatching trace']['expect']['callee'] = null; |
||
562 | $data['unmatching trace']['expect']['caller'] = null; |
||
563 | $data['unmatching trace']['expect']['trace'] = array_merge( |
||
564 | $basetrace, |
||
565 | array( |
||
566 | $dumpframe + array( |
||
567 | 'file' => TestClass::DUMP_FILE, |
||
568 | 'line' => TestClass::DUMP_LINE, |
||
569 | ), |
||
570 | ), |
||
571 | $basetrace |
||
572 | ); |
||
573 | |||
574 | $data['trace with params'] = array( |
||
575 | 'aliases' => $aliases, |
||
576 | 'trace' => array_merge( |
||
577 | array( |
||
578 | $dumpframe + array( |
||
579 | 'file' => TestClass::DUMP_FILE, |
||
580 | 'line' => TestClass::DUMP_LINE, |
||
581 | ), |
||
582 | ), |
||
583 | $basetrace |
||
584 | ), |
||
585 | 'param_count' => 3, |
||
586 | 'expect' => array( |
||
587 | 'params' => array( |
||
588 | array('name' => '$x', 'path' => '$x', 'expression' => false), |
||
589 | array('name' => '$y', 'path' => '$y', 'expression' => false), |
||
590 | array('name' => '$z', 'path' => '$z', 'expression' => false), |
||
591 | ), |
||
592 | 'modifiers' => array(), |
||
593 | 'callee' => $dumpframe + array( |
||
594 | 'file' => TestClass::DUMP_FILE, |
||
595 | 'line' => TestClass::DUMP_LINE, |
||
596 | ), |
||
597 | 'caller' => $basetrace[0], |
||
598 | 'trace' => array_merge( |
||
599 | array( |
||
600 | $dumpframe + array( |
||
601 | 'file' => TestClass::DUMP_FILE, |
||
602 | 'line' => TestClass::DUMP_LINE, |
||
603 | ), |
||
604 | ), |
||
605 | $basetrace |
||
606 | ), |
||
607 | ), |
||
608 | ); |
||
609 | |||
610 | $data['trace with modifiers'] = array( |
||
611 | 'aliases' => $aliases, |
||
612 | 'trace' => array_merge( |
||
613 | array( |
||
614 | $dumpframe + array( |
||
615 | 'file' => TestClass::DUMP_FILE, |
||
616 | 'line' => TestClass::DUMP_LINE + 1, |
||
617 | ), |
||
618 | ), |
||
619 | $basetrace |
||
620 | ), |
||
621 | 'param_count' => 0, |
||
622 | 'expect' => array( |
||
623 | 'params' => array(), |
||
624 | 'modifiers' => array('!', '+'), |
||
625 | 'callee' => $dumpframe + array( |
||
626 | 'file' => TestClass::DUMP_FILE, |
||
627 | 'line' => TestClass::DUMP_LINE + 1, |
||
628 | ), |
||
629 | 'caller' => $basetrace[0], |
||
630 | 'trace' => array_merge( |
||
631 | array( |
||
632 | $dumpframe + array( |
||
633 | 'file' => TestClass::DUMP_FILE, |
||
634 | 'line' => TestClass::DUMP_LINE + 1, |
||
635 | ), |
||
636 | ), |
||
637 | $basetrace |
||
638 | ), |
||
639 | ), |
||
640 | ); |
||
641 | |||
642 | $data['trace function with modifier'] = array( |
||
643 | 'aliases' => $aliases, |
||
644 | 'trace' => array_merge( |
||
645 | array( |
||
646 | array( |
||
647 | 'function' => 'd', |
||
648 | 'file' => TestClass::DUMP_FILE, |
||
649 | 'line' => TestClass::DUMP_LINE + 2, |
||
650 | ), |
||
651 | ), |
||
652 | $basetrace |
||
653 | ), |
||
654 | 'param_count' => 1, |
||
655 | 'expect' => array( |
||
656 | 'params' => array( |
||
657 | array( |
||
658 | 'name' => '$x', |
||
659 | 'path' => '$x', |
||
660 | 'expression' => false, |
||
661 | ), |
||
662 | ), |
||
663 | 'modifiers' => array('~'), |
||
664 | 'callee' => array( |
||
665 | 'function' => 'd', |
||
666 | 'file' => TestClass::DUMP_FILE, |
||
667 | 'line' => TestClass::DUMP_LINE + 2, |
||
668 | ), |
||
669 | 'caller' => $basetrace[0], |
||
670 | 'trace' => array_merge( |
||
671 | array( |
||
672 | array( |
||
673 | 'function' => 'd', |
||
674 | 'file' => TestClass::DUMP_FILE, |
||
675 | 'line' => TestClass::DUMP_LINE + 2, |
||
676 | ), |
||
677 | ), |
||
678 | $basetrace |
||
679 | ), |
||
680 | ), |
||
681 | ); |
||
682 | |||
683 | $data['trace function with multiple hits'] = array( |
||
684 | 'aliases' => $aliases, |
||
685 | 'trace' => array_merge( |
||
686 | array( |
||
687 | array( |
||
688 | 'function' => 'd', |
||
689 | 'file' => TestClass::DUMP_FILE, |
||
690 | 'line' => TestClass::DUMP_LINE + 3, |
||
691 | ), |
||
692 | ), |
||
693 | $basetrace |
||
694 | ), |
||
695 | 'param_count' => 1, |
||
696 | 'expect' => array( |
||
697 | 'params' => null, |
||
698 | 'modifiers' => array(), |
||
699 | 'callee' => array( |
||
700 | 'function' => 'd', |
||
701 | 'file' => TestClass::DUMP_FILE, |
||
702 | 'line' => TestClass::DUMP_LINE + 3, |
||
703 | ), |
||
704 | 'caller' => $basetrace[0], |
||
705 | 'trace' => array_merge( |
||
706 | array( |
||
707 | array( |
||
708 | 'function' => 'd', |
||
709 | 'file' => TestClass::DUMP_FILE, |
||
710 | 'line' => TestClass::DUMP_LINE + 3, |
||
711 | ), |
||
712 | ), |
||
713 | $basetrace |
||
714 | ), |
||
715 | ), |
||
716 | ); |
||
717 | |||
718 | // HHVM doesn't support multiple unpack parameters |
||
719 | if (KINT_PHP56 && !defined('HHVM_VERSION')) { |
||
720 | $data['trace with unpack'] = array( |
||
721 | 'aliases' => $aliases, |
||
722 | 'trace' => array_merge( |
||
723 | array( |
||
724 | $dumpframe + array( |
||
725 | 'file' => Php56TestClass::DUMP_FILE, |
||
726 | 'line' => Php56TestClass::DUMP_LINE, |
||
727 | ), |
||
728 | ), |
||
729 | $basetrace |
||
730 | ), |
||
731 | 'param_count' => 4, |
||
732 | 'expect' => array( |
||
733 | 'params' => array( |
||
734 | array( |
||
735 | 'name' => '$x', |
||
736 | 'path' => '$x', |
||
737 | 'expression' => false, |
||
738 | ), |
||
739 | array( |
||
740 | 'name' => '$y', |
||
741 | 'path' => '$y', |
||
742 | 'expression' => false, |
||
743 | ), |
||
744 | array( |
||
745 | 'name' => 'reset($z)', |
||
746 | 'path' => 'reset($z)', |
||
747 | 'expression' => false, |
||
748 | ), |
||
749 | array( |
||
750 | 'name' => 'array_values($z)[1]', |
||
751 | 'path' => 'array_values($z)[1]', |
||
752 | 'expression' => false, |
||
753 | ), |
||
754 | ), |
||
755 | 'modifiers' => array(), |
||
756 | 'callee' => $dumpframe + array( |
||
757 | 'file' => Php56TestClass::DUMP_FILE, |
||
758 | 'line' => Php56TestClass::DUMP_LINE, |
||
759 | ), |
||
760 | 'caller' => $basetrace[0], |
||
761 | 'trace' => array_merge( |
||
762 | array( |
||
763 | $dumpframe + array( |
||
764 | 'file' => Php56TestClass::DUMP_FILE, |
||
765 | 'line' => Php56TestClass::DUMP_LINE, |
||
766 | ), |
||
767 | ), |
||
768 | $basetrace |
||
769 | ), |
||
770 | ), |
||
771 | ); |
||
772 | |||
773 | $data['trace with double unpack'] = array( |
||
774 | 'aliases' => $aliases, |
||
775 | 'trace' => array_merge( |
||
776 | array( |
||
777 | $dumpframe + array( |
||
778 | 'file' => Php56TestClass::DUMP_FILE, |
||
779 | 'line' => Php56TestClass::DUMP_LINE + 1, |
||
780 | ), |
||
781 | ), |
||
782 | $basetrace |
||
783 | ), |
||
784 | 'param_count' => 10, |
||
785 | 'expect' => array( |
||
786 | 'params' => array(), |
||
787 | 'modifiers' => array(), |
||
788 | 'callee' => $dumpframe + array( |
||
789 | 'file' => Php56TestClass::DUMP_FILE, |
||
790 | 'line' => Php56TestClass::DUMP_LINE + 1, |
||
791 | ), |
||
792 | 'caller' => $basetrace[0], |
||
793 | 'trace' => array_merge( |
||
794 | array( |
||
795 | $dumpframe + array( |
||
796 | 'file' => Php56TestClass::DUMP_FILE, |
||
797 | 'line' => Php56TestClass::DUMP_LINE + 1, |
||
798 | ), |
||
799 | ), |
||
800 | $basetrace |
||
801 | ), |
||
802 | ), |
||
803 | ); |
||
804 | } |
||
805 | |||
806 | return $data; |
||
807 | } |
||
808 | |||
882 |
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.