| Conditions | 114 |
| Paths | > 20000 |
| Total Lines | 477 |
| Code Lines | 258 |
| Lines | 118 |
| Ratio | 24.74 % |
| 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 |
||
| 567 | private function recurseScopeMap($stackPtr, $depth=1, &$ignore=0) |
||
| 568 | { |
||
| 569 | if (PHP_CodeSniffer_VERBOSITY > 1) { |
||
| 570 | echo str_repeat("\t", $depth); |
||
| 571 | echo "=> Begin scope map recursion at token $stackPtr with depth $depth".PHP_EOL; |
||
| 572 | } |
||
| 573 | |||
| 574 | $opener = null; |
||
| 575 | $currType = $this->tokens[$stackPtr]['code']; |
||
| 576 | $startLine = $this->tokens[$stackPtr]['line']; |
||
| 577 | |||
| 578 | // We will need this to restore the value if we end up |
||
| 579 | // returning a token ID that causes our calling function to go back |
||
| 580 | // over already ignored braces. |
||
| 581 | $originalIgnore = $ignore; |
||
| 582 | |||
| 583 | // If the start token for this scope opener is the same as |
||
| 584 | // the scope token, we have already found our opener. |
||
| 585 | if (isset($this->scopeOpeners[$currType]['start'][$currType]) === true) { |
||
| 586 | $opener = $stackPtr; |
||
| 587 | } |
||
| 588 | |||
| 589 | for ($i = ($stackPtr + 1); $i < $this->numTokens; $i++) { |
||
| 590 | $tokenType = $this->tokens[$i]['code']; |
||
| 591 | |||
| 592 | if (PHP_CodeSniffer_VERBOSITY > 1) { |
||
| 593 | $type = $this->tokens[$i]['type']; |
||
| 594 | $line = $this->tokens[$i]['line']; |
||
| 595 | $content = Util\Common::prepareForOutput($this->tokens[$i]['content']); |
||
| 596 | |||
| 597 | echo str_repeat("\t", $depth); |
||
| 598 | echo "Process token $i on line $line ["; |
||
| 599 | if ($opener !== null) { |
||
| 600 | echo "opener:$opener;"; |
||
| 601 | } |
||
| 602 | |||
| 603 | if ($ignore > 0) { |
||
| 604 | echo "ignore=$ignore;"; |
||
| 605 | } |
||
| 606 | |||
| 607 | echo "]: $type => $content".PHP_EOL; |
||
| 608 | }//end if |
||
| 609 | |||
| 610 | // Very special case for IF statements in PHP that can be defined without |
||
| 611 | // scope tokens. E.g., if (1) 1; 1 ? (1 ? 1 : 1) : 1; |
||
| 612 | // If an IF statement below this one has an opener but no |
||
| 613 | // keyword, the opener will be incorrectly assigned to this IF statement. |
||
| 614 | if (($currType === T_IF || $currType === T_ELSE) |
||
| 615 | && $opener === null |
||
| 616 | && $this->tokens[$i]['code'] === T_SEMICOLON |
||
| 617 | ) { |
||
| 618 | View Code Duplication | if (PHP_CodeSniffer_VERBOSITY > 1) { |
|
| 619 | $type = $this->tokens[$stackPtr]['type']; |
||
| 620 | echo str_repeat("\t", $depth); |
||
| 621 | echo "=> Found semicolon before scope opener for $stackPtr:$type, bailing".PHP_EOL; |
||
| 622 | } |
||
| 623 | |||
| 624 | return $i; |
||
| 625 | } |
||
| 626 | |||
| 627 | // Special case for PHP control structures that have no braces. |
||
| 628 | // If we find a curly brace closer before we find the opener, |
||
| 629 | // we're not going to find an opener. That closer probably belongs to |
||
| 630 | // a control structure higher up. |
||
| 631 | if ($opener === null |
||
| 632 | && $ignore === 0 |
||
| 633 | && $tokenType === T_CLOSE_CURLY_BRACKET |
||
| 634 | && isset($this->scopeOpeners[$currType]['end'][$tokenType]) === true |
||
| 635 | ) { |
||
| 636 | View Code Duplication | if (PHP_CodeSniffer_VERBOSITY > 1) { |
|
| 637 | $type = $this->tokens[$stackPtr]['type']; |
||
| 638 | echo str_repeat("\t", $depth); |
||
| 639 | echo "=> Found curly brace closer before scope opener for $stackPtr:$type, bailing".PHP_EOL; |
||
| 640 | } |
||
| 641 | |||
| 642 | return ($i - 1); |
||
| 643 | } |
||
| 644 | |||
| 645 | if ($opener !== null |
||
| 646 | && (isset($this->tokens[$i]['scope_opener']) === false |
||
| 647 | || $this->scopeOpeners[$this->tokens[$stackPtr]['code']]['shared'] === true) |
||
| 648 | && isset($this->scopeOpeners[$currType]['end'][$tokenType]) === true |
||
| 649 | ) { |
||
| 650 | if ($ignore > 0 && $tokenType === T_CLOSE_CURLY_BRACKET) { |
||
| 651 | // The last opening bracket must have been for a string |
||
| 652 | // offset or alike, so let's ignore it. |
||
| 653 | if (PHP_CodeSniffer_VERBOSITY > 1) { |
||
| 654 | echo str_repeat("\t", $depth); |
||
| 655 | echo '* finished ignoring curly brace *'.PHP_EOL; |
||
| 656 | } |
||
| 657 | |||
| 658 | $ignore--; |
||
| 659 | continue; |
||
| 660 | } else if ($this->tokens[$opener]['code'] === T_OPEN_CURLY_BRACKET |
||
| 661 | && $tokenType !== T_CLOSE_CURLY_BRACKET |
||
| 662 | ) { |
||
| 663 | // The opener is a curly bracket so the closer must be a curly bracket as well. |
||
| 664 | // We ignore this closer to handle cases such as T_ELSE or T_ELSEIF being considered |
||
| 665 | // a closer of T_IF when it should not. |
||
| 666 | View Code Duplication | if (PHP_CodeSniffer_VERBOSITY > 1) { |
|
| 667 | $type = $this->tokens[$stackPtr]['type']; |
||
| 668 | echo str_repeat("\t", $depth); |
||
| 669 | echo "=> Ignoring non-curly scope closer for $stackPtr:$type".PHP_EOL; |
||
| 670 | } |
||
| 671 | } else { |
||
| 672 | $scopeCloser = $i; |
||
| 673 | $todo = array( |
||
| 674 | $stackPtr, |
||
| 675 | $opener, |
||
| 676 | ); |
||
| 677 | |||
| 678 | View Code Duplication | if (PHP_CodeSniffer_VERBOSITY > 1) { |
|
| 679 | $type = $this->tokens[$stackPtr]['type']; |
||
| 680 | $closerType = $this->tokens[$scopeCloser]['type']; |
||
| 681 | echo str_repeat("\t", $depth); |
||
| 682 | echo "=> Found scope closer ($scopeCloser:$closerType) for $stackPtr:$type".PHP_EOL; |
||
| 683 | } |
||
| 684 | |||
| 685 | $validCloser = true; |
||
| 686 | if (($this->tokens[$stackPtr]['code'] === T_IF || $this->tokens[$stackPtr]['code'] === T_ELSEIF) |
||
| 687 | && ($tokenType === T_ELSE || $tokenType === T_ELSEIF) |
||
| 688 | ) { |
||
| 689 | // To be a closer, this token must have an opener. |
||
| 690 | if (PHP_CodeSniffer_VERBOSITY > 1) { |
||
| 691 | echo str_repeat("\t", $depth); |
||
| 692 | echo "* closer needs to be tested *".PHP_EOL; |
||
| 693 | } |
||
| 694 | |||
| 695 | $i = self::recurseScopeMap($i, ($depth + 1), $ignore); |
||
| 696 | |||
| 697 | if (isset($this->tokens[$scopeCloser]['scope_opener']) === false) { |
||
| 698 | $validCloser = false; |
||
| 699 | if (PHP_CodeSniffer_VERBOSITY > 1) { |
||
| 700 | echo str_repeat("\t", $depth); |
||
| 701 | echo "* closer is not valid (no opener found) *".PHP_EOL; |
||
| 702 | } |
||
| 703 | } else if ($this->tokens[$this->tokens[$scopeCloser]['scope_opener']]['code'] !== $this->tokens[$opener]['code']) { |
||
| 704 | $validCloser = false; |
||
| 705 | if (PHP_CodeSniffer_VERBOSITY > 1) { |
||
| 706 | echo str_repeat("\t", $depth); |
||
| 707 | $type = $this->tokens[$this->tokens[$scopeCloser]['scope_opener']]['type']; |
||
| 708 | $openerType = $this->tokens[$opener]['type']; |
||
| 709 | echo "* closer is not valid (mismatched opener type; $type != $openerType) *".PHP_EOL; |
||
| 710 | } |
||
| 711 | } else if (PHP_CodeSniffer_VERBOSITY > 1) { |
||
| 712 | echo str_repeat("\t", $depth); |
||
| 713 | echo "* closer was valid *".PHP_EOL; |
||
| 714 | } |
||
| 715 | } else { |
||
| 716 | // The closer was not processed, so we need to |
||
| 717 | // complete that token as well. |
||
| 718 | $todo[] = $scopeCloser; |
||
| 719 | }//end if |
||
| 720 | |||
| 721 | if ($validCloser === true) { |
||
| 722 | foreach ($todo as $token) { |
||
| 723 | $this->tokens[$token]['scope_condition'] = $stackPtr; |
||
| 724 | $this->tokens[$token]['scope_opener'] = $opener; |
||
| 725 | $this->tokens[$token]['scope_closer'] = $scopeCloser; |
||
| 726 | } |
||
| 727 | |||
| 728 | if ($this->scopeOpeners[$this->tokens[$stackPtr]['code']]['shared'] === true) { |
||
| 729 | // As we are going back to where we started originally, restore |
||
| 730 | // the ignore value back to its original value. |
||
| 731 | $ignore = $originalIgnore; |
||
| 732 | return $opener; |
||
| 733 | } else if ($scopeCloser === $i |
||
| 734 | && isset($this->scopeOpeners[$tokenType]) === true |
||
| 735 | ) { |
||
| 736 | // Unset scope_condition here or else the token will appear to have |
||
| 737 | // already been processed, and it will be skipped. Normally we want that, |
||
| 738 | // but in this case, the token is both a closer and an opener, so |
||
| 739 | // it needs to act like an opener. This is also why we return the |
||
| 740 | // token before this one; so the closer has a chance to be processed |
||
| 741 | // a second time, but as an opener. |
||
| 742 | unset($this->tokens[$scopeCloser]['scope_condition']); |
||
| 743 | return ($i - 1); |
||
| 744 | } else { |
||
| 745 | return $i; |
||
| 746 | } |
||
| 747 | } else { |
||
| 748 | continue; |
||
| 749 | }//end if |
||
| 750 | }//end if |
||
| 751 | }//end if |
||
| 752 | |||
| 753 | // Is this an opening condition ? |
||
| 754 | if (isset($this->scopeOpeners[$tokenType]) === true) { |
||
| 755 | if ($opener === null) { |
||
| 756 | if ($tokenType === T_USE) { |
||
| 757 | // PHP use keywords are special because they can be |
||
| 758 | // used as blocks but also inline in function definitions. |
||
| 759 | // So if we find them nested inside another opener, just skip them. |
||
| 760 | continue; |
||
| 761 | } |
||
| 762 | |||
| 763 | if ($tokenType === T_FUNCTION |
||
| 764 | && $this->tokens[$stackPtr]['code'] !== T_FUNCTION |
||
| 765 | ) { |
||
| 766 | // Probably a closure, so process it manually. |
||
| 767 | View Code Duplication | if (PHP_CodeSniffer_VERBOSITY > 1) { |
|
| 768 | $type = $this->tokens[$stackPtr]['type']; |
||
| 769 | echo str_repeat("\t", $depth); |
||
| 770 | echo "=> Found function before scope opener for $stackPtr:$type, processing manually".PHP_EOL; |
||
| 771 | } |
||
| 772 | |||
| 773 | View Code Duplication | if (isset($this->tokens[$i]['scope_closer']) === true) { |
|
| 774 | // We've already processed this closure. |
||
| 775 | if (PHP_CodeSniffer_VERBOSITY > 1) { |
||
| 776 | echo str_repeat("\t", $depth); |
||
| 777 | echo '* already processed, skipping *'.PHP_EOL; |
||
| 778 | } |
||
| 779 | |||
| 780 | $i = $this->tokens[$i]['scope_closer']; |
||
| 781 | continue; |
||
| 782 | } |
||
| 783 | |||
| 784 | $i = self::recurseScopeMap($i, ($depth + 1), $ignore); |
||
| 785 | continue; |
||
| 786 | }//end if |
||
| 787 | |||
| 788 | // Found another opening condition but still haven't |
||
| 789 | // found our opener, so we are never going to find one. |
||
| 790 | View Code Duplication | if (PHP_CodeSniffer_VERBOSITY > 1) { |
|
| 791 | $type = $this->tokens[$stackPtr]['type']; |
||
| 792 | echo str_repeat("\t", $depth); |
||
| 793 | echo "=> Found new opening condition before scope opener for $stackPtr:$type, "; |
||
| 794 | } |
||
| 795 | |||
| 796 | if (($this->tokens[$stackPtr]['code'] === T_IF |
||
| 797 | || $this->tokens[$stackPtr]['code'] === T_ELSEIF |
||
| 798 | || $this->tokens[$stackPtr]['code'] === T_ELSE) |
||
| 799 | && ($this->tokens[$i]['code'] === T_ELSE |
||
| 800 | || $this->tokens[$i]['code'] === T_ELSEIF) |
||
| 801 | ) { |
||
| 802 | if (PHP_CodeSniffer_VERBOSITY > 1) { |
||
| 803 | echo "continuing".PHP_EOL; |
||
| 804 | } |
||
| 805 | |||
| 806 | return ($i - 1); |
||
| 807 | } else { |
||
| 808 | if (PHP_CodeSniffer_VERBOSITY > 1) { |
||
| 809 | echo "backtracking".PHP_EOL; |
||
| 810 | } |
||
| 811 | |||
| 812 | return $stackPtr; |
||
| 813 | } |
||
| 814 | }//end if |
||
| 815 | |||
| 816 | if (PHP_CodeSniffer_VERBOSITY > 1) { |
||
| 817 | echo str_repeat("\t", $depth); |
||
| 818 | echo '* token is an opening condition *'.PHP_EOL; |
||
| 819 | } |
||
| 820 | |||
| 821 | $isShared = ($this->scopeOpeners[$tokenType]['shared'] === true); |
||
| 822 | |||
| 823 | if (isset($this->tokens[$i]['scope_condition']) === true) { |
||
| 824 | // We've been here before. |
||
| 825 | if (PHP_CodeSniffer_VERBOSITY > 1) { |
||
| 826 | echo str_repeat("\t", $depth); |
||
| 827 | echo '* already processed, skipping *'.PHP_EOL; |
||
| 828 | } |
||
| 829 | |||
| 830 | View Code Duplication | if ($isShared === false |
|
| 831 | && isset($this->tokens[$i]['scope_closer']) === true |
||
| 832 | ) { |
||
| 833 | $i = $this->tokens[$i]['scope_closer']; |
||
| 834 | } |
||
| 835 | |||
| 836 | continue; |
||
| 837 | } else if ($currType === $tokenType |
||
| 838 | && $isShared === false |
||
| 839 | && $opener === null |
||
| 840 | ) { |
||
| 841 | // We haven't yet found our opener, but we have found another |
||
| 842 | // scope opener which is the same type as us, and we don't |
||
| 843 | // share openers, so we will never find one. |
||
| 844 | if (PHP_CodeSniffer_VERBOSITY > 1) { |
||
| 845 | echo str_repeat("\t", $depth); |
||
| 846 | echo '* it was another token\'s opener, bailing *'.PHP_EOL; |
||
| 847 | } |
||
| 848 | |||
| 849 | return $stackPtr; |
||
| 850 | } else { |
||
| 851 | if (PHP_CodeSniffer_VERBOSITY > 1) { |
||
| 852 | echo str_repeat("\t", $depth); |
||
| 853 | echo '* searching for opener *'.PHP_EOL; |
||
| 854 | } |
||
| 855 | |||
| 856 | View Code Duplication | if (isset($this->scopeOpeners[$tokenType]['end'][T_CLOSE_CURLY_BRACKET]) === true) { |
|
| 857 | $oldIgnore = $ignore; |
||
| 858 | $ignore = 0; |
||
| 859 | } |
||
| 860 | |||
| 861 | // PHP has a max nesting level for functions. Stop before we hit that limit |
||
| 862 | // because too many loops means we've run into trouble anyway. |
||
| 863 | View Code Duplication | if ($depth > 50) { |
|
| 864 | if (PHP_CodeSniffer_VERBOSITY > 1) { |
||
| 865 | echo str_repeat("\t", $depth); |
||
| 866 | echo '* reached maximum nesting level; aborting *'.PHP_EOL; |
||
| 867 | } |
||
| 868 | |||
| 869 | throw new RuntimeException('Maximum nesting level reached; file could not be processed'); |
||
| 870 | } |
||
| 871 | |||
| 872 | $oldDepth = $depth; |
||
| 873 | if ($isShared === true |
||
| 874 | && isset($this->scopeOpeners[$tokenType]['with'][$currType]) === true |
||
| 875 | ) { |
||
| 876 | // Don't allow the depth to increment because this is |
||
| 877 | // possibly not a true nesting if we are sharing our closer. |
||
| 878 | // This can happen, for example, when a SWITCH has a large |
||
| 879 | // number of CASE statements with the same shared BREAK. |
||
| 880 | $depth--; |
||
| 881 | } |
||
| 882 | |||
| 883 | $i = self::recurseScopeMap($i, ($depth + 1), $ignore); |
||
| 884 | $depth = $oldDepth; |
||
| 885 | |||
| 886 | View Code Duplication | if (isset($this->scopeOpeners[$tokenType]['end'][T_CLOSE_CURLY_BRACKET]) === true) { |
|
| 887 | $ignore = $oldIgnore; |
||
| 888 | } |
||
| 889 | }//end if |
||
| 890 | }//end if |
||
| 891 | |||
| 892 | if (isset($this->scopeOpeners[$currType]['start'][$tokenType]) === true |
||
| 893 | && $opener === null |
||
| 894 | ) { |
||
| 895 | if ($tokenType === T_OPEN_CURLY_BRACKET) { |
||
| 896 | if (isset($this->tokens[$stackPtr]['parenthesis_closer']) === true |
||
| 897 | && $i < $this->tokens[$stackPtr]['parenthesis_closer'] |
||
| 898 | ) { |
||
| 899 | // We found a curly brace inside the condition of the |
||
| 900 | // current scope opener, so it must be a string offset. |
||
| 901 | if (PHP_CodeSniffer_VERBOSITY > 1) { |
||
| 902 | echo str_repeat("\t", $depth); |
||
| 903 | echo '* ignoring curly brace *'.PHP_EOL; |
||
| 904 | } |
||
| 905 | |||
| 906 | $ignore++; |
||
| 907 | } else { |
||
| 908 | // Make sure this is actually an opener and not a |
||
| 909 | // string offset (e.g., $var{0}). |
||
| 910 | for ($x = ($i - 1); $x > 0; $x--) { |
||
| 911 | if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]) === true) { |
||
| 912 | continue; |
||
| 913 | View Code Duplication | } else { |
|
| 914 | // If the first non-whitespace/comment token is a |
||
| 915 | // variable or object operator then this is an opener |
||
| 916 | // for a string offset and not a scope. |
||
| 917 | if ($this->tokens[$x]['code'] === T_VARIABLE |
||
| 918 | || $this->tokens[$x]['code'] === T_OBJECT_OPERATOR |
||
| 919 | ) { |
||
| 920 | if (PHP_CodeSniffer_VERBOSITY > 1) { |
||
| 921 | echo str_repeat("\t", $depth); |
||
| 922 | echo '* ignoring curly brace *'.PHP_EOL; |
||
| 923 | } |
||
| 924 | |||
| 925 | $ignore++; |
||
| 926 | }//end if |
||
| 927 | |||
| 928 | break; |
||
| 929 | }//end if |
||
| 930 | }//end for |
||
| 931 | }//end if |
||
| 932 | }//end if |
||
| 933 | |||
| 934 | if ($ignore === 0 || $tokenType !== T_OPEN_CURLY_BRACKET) { |
||
| 935 | // We found the opening scope token for $currType. |
||
| 936 | View Code Duplication | if (PHP_CodeSniffer_VERBOSITY > 1) { |
|
| 937 | $type = $this->tokens[$stackPtr]['type']; |
||
| 938 | echo str_repeat("\t", $depth); |
||
| 939 | echo "=> Found scope opener for $stackPtr:$type".PHP_EOL; |
||
| 940 | } |
||
| 941 | |||
| 942 | $opener = $i; |
||
| 943 | } |
||
| 944 | } else if ($tokenType === T_OPEN_PARENTHESIS) { |
||
| 945 | if (isset($this->tokens[$i]['parenthesis_owner']) === true) { |
||
| 946 | $owner = $this->tokens[$i]['parenthesis_owner']; |
||
| 947 | View Code Duplication | if (isset(Util\Tokens::$scopeOpeners[$this->tokens[$owner]['code']]) === true |
|
| 948 | && isset($this->tokens[$i]['parenthesis_closer']) === true |
||
| 949 | ) { |
||
| 950 | // If we get into here, then we opened a parenthesis for |
||
| 951 | // a scope (eg. an if or else if) so we need to update the |
||
| 952 | // start of the line so that when we check to see |
||
| 953 | // if the closing parenthesis is more than 3 lines away from |
||
| 954 | // the statement, we check from the closing parenthesis. |
||
| 955 | $startLine = $this->tokens[$this->tokens[$i]['parenthesis_closer']]['line']; |
||
| 956 | } |
||
| 957 | } |
||
| 958 | } else if ($tokenType === T_OPEN_CURLY_BRACKET && $opener !== null) { |
||
| 959 | // We opened something that we don't have a scope opener for. |
||
| 960 | // Examples of this are curly brackets for string offsets etc. |
||
| 961 | // We want to ignore this so that we don't have an invalid scope |
||
| 962 | // map. |
||
| 963 | if (PHP_CodeSniffer_VERBOSITY > 1) { |
||
| 964 | echo str_repeat("\t", $depth); |
||
| 965 | echo '* ignoring curly brace *'.PHP_EOL; |
||
| 966 | } |
||
| 967 | |||
| 968 | $ignore++; |
||
| 969 | } else if ($tokenType === T_CLOSE_CURLY_BRACKET && $ignore > 0) { |
||
| 970 | // We found the end token for the opener we were ignoring. |
||
| 971 | if (PHP_CodeSniffer_VERBOSITY > 1) { |
||
| 972 | echo str_repeat("\t", $depth); |
||
| 973 | echo '* finished ignoring curly brace *'.PHP_EOL; |
||
| 974 | } |
||
| 975 | |||
| 976 | $ignore--; |
||
| 977 | } else if ($opener === null |
||
| 978 | && isset($this->scopeOpeners[$currType]) === true |
||
| 979 | ) { |
||
| 980 | // If we still haven't found the opener after 3 lines, |
||
| 981 | // we're not going to find it, unless we know it requires |
||
| 982 | // an opener (in which case we better keep looking) or the last |
||
| 983 | // token was empty (in which case we'll just confirm there is |
||
| 984 | // more code in this file and not just a big comment). |
||
| 985 | if ($this->tokens[$i]['line'] >= ($startLine + 3) |
||
| 986 | && isset(Util\Tokens::$emptyTokens[$this->tokens[($i - 1)]['code']]) === false |
||
| 987 | ) { |
||
| 988 | if ($this->scopeOpeners[$currType]['strict'] === true) { |
||
| 989 | View Code Duplication | if (PHP_CodeSniffer_VERBOSITY > 1) { |
|
| 990 | $type = $this->tokens[$stackPtr]['type']; |
||
| 991 | $lines = ($this->tokens[$i]['line'] - $startLine); |
||
| 992 | echo str_repeat("\t", $depth); |
||
| 993 | echo "=> Still looking for $stackPtr:$type scope opener after $lines lines".PHP_EOL; |
||
| 994 | } |
||
| 995 | View Code Duplication | } else { |
|
| 996 | if (PHP_CodeSniffer_VERBOSITY > 1) { |
||
| 997 | $type = $this->tokens[$stackPtr]['type']; |
||
| 998 | echo str_repeat("\t", $depth); |
||
| 999 | echo "=> Couldn't find scope opener for $stackPtr:$type, bailing".PHP_EOL; |
||
| 1000 | } |
||
| 1001 | |||
| 1002 | return $stackPtr; |
||
| 1003 | } |
||
| 1004 | } |
||
| 1005 | } else if ($opener !== null |
||
| 1006 | && $tokenType !== T_BREAK |
||
| 1007 | && isset($this->endScopeTokens[$tokenType]) === true |
||
| 1008 | ) { |
||
| 1009 | if (isset($this->tokens[$i]['scope_condition']) === false) { |
||
| 1010 | if ($ignore > 0) { |
||
| 1011 | // We found the end token for the opener we were ignoring. |
||
| 1012 | if (PHP_CodeSniffer_VERBOSITY > 1) { |
||
| 1013 | echo str_repeat("\t", $depth); |
||
| 1014 | echo '* finished ignoring curly brace *'.PHP_EOL; |
||
| 1015 | } |
||
| 1016 | |||
| 1017 | $ignore--; |
||
| 1018 | } else { |
||
| 1019 | // We found a token that closes the scope but it doesn't |
||
| 1020 | // have a condition, so it belongs to another token and |
||
| 1021 | // our token doesn't have a closer, so pretend this is |
||
| 1022 | // the closer. |
||
| 1023 | View Code Duplication | if (PHP_CodeSniffer_VERBOSITY > 1) { |
|
| 1024 | $type = $this->tokens[$stackPtr]['type']; |
||
| 1025 | echo str_repeat("\t", $depth); |
||
| 1026 | echo "=> Found (unexpected) scope closer for $stackPtr:$type".PHP_EOL; |
||
| 1027 | } |
||
| 1028 | |||
| 1029 | View Code Duplication | foreach (array($stackPtr, $opener) as $token) { |
|
| 1030 | $this->tokens[$token]['scope_condition'] = $stackPtr; |
||
| 1031 | $this->tokens[$token]['scope_opener'] = $opener; |
||
| 1032 | $this->tokens[$token]['scope_closer'] = $i; |
||
| 1033 | } |
||
| 1034 | |||
| 1035 | return ($i - 1); |
||
| 1036 | }//end if |
||
| 1037 | }//end if |
||
| 1038 | }//end if |
||
| 1039 | }//end for |
||
| 1040 | |||
| 1041 | return $stackPtr; |
||
| 1042 | |||
| 1043 | }//end recurseScopeMap() |
||
| 1044 | |||
| 1291 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.