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