@@ -501,10 +501,10 @@ discard block |
||
501 | 501 | protected function get_last_ptr_on_line( $stackPtr ) { |
502 | 502 | |
503 | 503 | $tokens = $this->tokens; |
504 | - $currentLine = $tokens[ $stackPtr ]['line']; |
|
504 | + $currentLine = $tokens[ $stackPtr ][ 'line' ]; |
|
505 | 505 | $nextPtr = ( $stackPtr + 1 ); |
506 | 506 | |
507 | - while ( isset( $tokens[ $nextPtr ] ) && $tokens[ $nextPtr ]['line'] === $currentLine ) { |
|
507 | + while ( isset( $tokens[ $nextPtr ] ) && $tokens[ $nextPtr ][ 'line' ] === $currentLine ) { |
|
508 | 508 | $nextPtr++; |
509 | 509 | // Do nothing, we just want the last token of the line. |
510 | 510 | } |
@@ -552,7 +552,7 @@ discard block |
||
552 | 552 | // If the statement was ended by a semicolon, we find the next non- |
553 | 553 | // whitespace token. If the semicolon was left out and it was terminated |
554 | 554 | // by an ending tag, we need to look backwards. |
555 | - if ( T_SEMICOLON === $this->tokens[ $end_of_statement ]['code'] ) { |
|
555 | + if ( T_SEMICOLON === $this->tokens[ $end_of_statement ][ 'code' ] ) { |
|
556 | 556 | $lastPtr = $this->phpcsFile->findNext( T_WHITESPACE, ( $end_of_statement + 1 ), null, true ); |
557 | 557 | } else { |
558 | 558 | $lastPtr = $this->phpcsFile->findPrevious( T_WHITESPACE, ( $end_of_statement - 1 ), null, true ); |
@@ -561,8 +561,8 @@ discard block |
||
561 | 561 | |
562 | 562 | $last = $this->tokens[ $lastPtr ]; |
563 | 563 | |
564 | - if ( T_COMMENT === $last['code'] ) { |
|
565 | - return preg_match( '#' . preg_quote( $comment ) . '#i', $last['content'] ); |
|
564 | + if ( T_COMMENT === $last[ 'code' ] ) { |
|
565 | + return preg_match( '#' . preg_quote( $comment ) . '#i', $last[ 'content' ] ); |
|
566 | 566 | } else { |
567 | 567 | return false; |
568 | 568 | } |
@@ -589,7 +589,7 @@ discard block |
||
589 | 589 | $tokens = $this->phpcsFile->getTokens(); |
590 | 590 | |
591 | 591 | // Must be a variable or closing square bracket (see below). |
592 | - if ( ! in_array( $tokens[ $stackPtr ]['code'], array( T_VARIABLE, T_CLOSE_SQUARE_BRACKET ), true ) ) { |
|
592 | + if ( ! in_array( $tokens[ $stackPtr ][ 'code' ], array( T_VARIABLE, T_CLOSE_SQUARE_BRACKET ), true ) ) { |
|
593 | 593 | return false; |
594 | 594 | } |
595 | 595 | |
@@ -608,13 +608,13 @@ discard block |
||
608 | 608 | } |
609 | 609 | |
610 | 610 | // If the next token is an assignment, that's all we need to know. |
611 | - if ( in_array( $tokens[ $next_non_empty ]['code'], PHP_CodeSniffer_Tokens::$assignmentTokens, true ) ) { |
|
611 | + if ( in_array( $tokens[ $next_non_empty ][ 'code' ], PHP_CodeSniffer_Tokens::$assignmentTokens, true ) ) { |
|
612 | 612 | return true; |
613 | 613 | } |
614 | 614 | |
615 | 615 | // Check if this is an array assignment, e.g., `$var['key'] = 'val';` . |
616 | - if ( T_OPEN_SQUARE_BRACKET === $tokens[ $next_non_empty ]['code'] ) { |
|
617 | - return $this->is_assignment( $tokens[ $next_non_empty ]['bracket_closer'] ); |
|
616 | + if ( T_OPEN_SQUARE_BRACKET === $tokens[ $next_non_empty ][ 'code' ] ) { |
|
617 | + return $this->is_assignment( $tokens[ $next_non_empty ][ 'bracket_closer' ] ); |
|
618 | 618 | } |
619 | 619 | |
620 | 620 | return false; |
@@ -652,7 +652,7 @@ discard block |
||
652 | 652 | // If we're in a function, only look inside of it. |
653 | 653 | $f = $this->phpcsFile->getCondition( $stackPtr, T_FUNCTION ); |
654 | 654 | if ( $f ) { |
655 | - $start = $tokens[ $f ]['scope_opener']; |
|
655 | + $start = $tokens[ $f ][ 'scope_opener' ]; |
|
656 | 656 | } |
657 | 657 | |
658 | 658 | $in_isset = $this->is_in_isset_or_empty( $stackPtr ); |
@@ -661,23 +661,23 @@ discard block |
||
661 | 661 | // If this is inside an isset(), check after it as well, all the way to the |
662 | 662 | // end of the scope. |
663 | 663 | if ( $in_isset ) { |
664 | - $end = ( 0 === $start ) ? count( $tokens ) : $tokens[ $start ]['scope_closer']; |
|
664 | + $end = ( 0 === $start ) ? count( $tokens ) : $tokens[ $start ][ 'scope_closer' ]; |
|
665 | 665 | } |
666 | 666 | |
667 | 667 | // Check if we've looked here before. |
668 | 668 | $filename = $this->phpcsFile->getFilename(); |
669 | 669 | |
670 | 670 | if ( |
671 | - $filename === $last['file'] |
|
672 | - && $start === $last['start'] |
|
671 | + $filename === $last[ 'file' ] |
|
672 | + && $start === $last[ 'start' ] |
|
673 | 673 | ) { |
674 | 674 | |
675 | - if ( false !== $last['nonce_check'] ) { |
|
675 | + if ( false !== $last[ 'nonce_check' ] ) { |
|
676 | 676 | // If we have already found an nonce check in this scope, we just |
677 | 677 | // need to check whether it comes before this token. It is OK if the |
678 | 678 | // check is after the token though, if this was only a isset() check. |
679 | - return ( $in_isset || $last['nonce_check'] < $stackPtr ); |
|
680 | - } elseif ( $end <= $last['end'] ) { |
|
679 | + return ( $in_isset || $last[ 'nonce_check' ] < $stackPtr ); |
|
680 | + } elseif ( $end <= $last[ 'end' ] ) { |
|
681 | 681 | // If not, we can still go ahead and return false if we've already |
682 | 682 | // checked to the end of the search area. |
683 | 683 | return false; |
@@ -685,7 +685,7 @@ discard block |
||
685 | 685 | |
686 | 686 | // We haven't checked this far yet, but we can still save work by |
687 | 687 | // skipping over the part we've already checked. |
688 | - $start = $last['end']; |
|
688 | + $start = $last[ 'end' ]; |
|
689 | 689 | } else { |
690 | 690 | $last = array( |
691 | 691 | 'file' => $filename, |
@@ -698,19 +698,19 @@ discard block |
||
698 | 698 | for ( $i = $start; $i < $end; $i++ ) { |
699 | 699 | |
700 | 700 | // If this isn't a function name, skip it. |
701 | - if ( T_STRING !== $tokens[ $i ]['code'] ) { |
|
701 | + if ( T_STRING !== $tokens[ $i ][ 'code' ] ) { |
|
702 | 702 | continue; |
703 | 703 | } |
704 | 704 | |
705 | 705 | // If this is one of the nonce verification functions, we can bail out. |
706 | - if ( isset( self::$nonceVerificationFunctions[ $tokens[ $i ]['content'] ] ) ) { |
|
707 | - $last['nonce_check'] = $i; |
|
706 | + if ( isset( self::$nonceVerificationFunctions[ $tokens[ $i ][ 'content' ] ] ) ) { |
|
707 | + $last[ 'nonce_check' ] = $i; |
|
708 | 708 | return true; |
709 | 709 | } |
710 | 710 | } |
711 | 711 | |
712 | 712 | // We're still here, so no luck. |
713 | - $last['nonce_check'] = false; |
|
713 | + $last[ 'nonce_check' ] = false; |
|
714 | 714 | |
715 | 715 | return false; |
716 | 716 | } |
@@ -726,15 +726,15 @@ discard block |
||
726 | 726 | */ |
727 | 727 | protected function is_in_isset_or_empty( $stackPtr ) { |
728 | 728 | |
729 | - if ( ! isset( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) ) { |
|
729 | + if ( ! isset( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) ) { |
|
730 | 730 | return false; |
731 | 731 | } |
732 | 732 | |
733 | - end( $this->tokens[ $stackPtr ]['nested_parenthesis'] ); |
|
734 | - $open_parenthesis = key( $this->tokens[ $stackPtr ]['nested_parenthesis'] ); |
|
735 | - reset( $this->tokens[ $stackPtr ]['nested_parenthesis'] ); |
|
733 | + end( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ); |
|
734 | + $open_parenthesis = key( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ); |
|
735 | + reset( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ); |
|
736 | 736 | |
737 | - return in_array( $this->tokens[ ( $open_parenthesis - 1 ) ]['code'], array( T_ISSET, T_EMPTY ), true ); |
|
737 | + return in_array( $this->tokens[ ( $open_parenthesis - 1 ) ][ 'code' ], array( T_ISSET, T_EMPTY ), true ); |
|
738 | 738 | } |
739 | 739 | |
740 | 740 | /** |
@@ -755,7 +755,7 @@ discard block |
||
755 | 755 | |
756 | 756 | // If this isn't set, we know the value must have only been casted, because |
757 | 757 | // is_sanitized() would have returned false otherwise. |
758 | - if ( ! isset( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) ) { |
|
758 | + if ( ! isset( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) ) { |
|
759 | 759 | return true; |
760 | 760 | } |
761 | 761 | |
@@ -767,7 +767,7 @@ discard block |
||
767 | 767 | |
768 | 768 | // The only parentheses should belong to the sanitizing function. If there's |
769 | 769 | // more than one set, this isn't *only* sanitization. |
770 | - return ( count( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) === 1 ); |
|
770 | + return ( count( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) === 1 ); |
|
771 | 771 | } |
772 | 772 | |
773 | 773 | /** |
@@ -790,7 +790,7 @@ discard block |
||
790 | 790 | ); |
791 | 791 | |
792 | 792 | // Check if it is a safe cast. |
793 | - return in_array( $this->tokens[ $prev ]['code'], array( T_INT_CAST, T_DOUBLE_CAST, T_BOOL_CAST ), true ); |
|
793 | + return in_array( $this->tokens[ $prev ][ 'code' ], array( T_INT_CAST, T_DOUBLE_CAST, T_BOOL_CAST ), true ); |
|
794 | 794 | } |
795 | 795 | |
796 | 796 | /** |
@@ -812,7 +812,7 @@ discard block |
||
812 | 812 | } |
813 | 813 | |
814 | 814 | // If this isn't within a function call, we know already that it's not safe. |
815 | - if ( ! isset( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) ) { |
|
815 | + if ( ! isset( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) ) { |
|
816 | 816 | if ( $require_unslash ) { |
817 | 817 | $this->add_unslash_error( $stackPtr ); |
818 | 818 | } |
@@ -820,38 +820,38 @@ discard block |
||
820 | 820 | } |
821 | 821 | |
822 | 822 | // Get the function that it's in. |
823 | - $function_closer = end( $this->tokens[ $stackPtr ]['nested_parenthesis'] ); |
|
824 | - $function_opener = key( $this->tokens[ $stackPtr ]['nested_parenthesis'] ); |
|
823 | + $function_closer = end( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ); |
|
824 | + $function_opener = key( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ); |
|
825 | 825 | $function = $this->tokens[ ( $function_opener - 1 ) ]; |
826 | 826 | |
827 | 827 | // If it is just being unset, the value isn't used at all, so it's safe. |
828 | - if ( T_UNSET === $function['code'] ) { |
|
828 | + if ( T_UNSET === $function[ 'code' ] ) { |
|
829 | 829 | return true; |
830 | 830 | } |
831 | 831 | |
832 | 832 | // If this isn't a call to a function, it sure isn't sanitizing function. |
833 | - if ( T_STRING !== $function['code'] ) { |
|
833 | + if ( T_STRING !== $function[ 'code' ] ) { |
|
834 | 834 | if ( $require_unslash ) { |
835 | 835 | $this->add_unslash_error( $stackPtr ); |
836 | 836 | } |
837 | 837 | return false; |
838 | 838 | } |
839 | 839 | |
840 | - $functionName = $function['content']; |
|
840 | + $functionName = $function[ 'content' ]; |
|
841 | 841 | |
842 | 842 | // Check if wp_unslash() is being used. |
843 | 843 | if ( 'wp_unslash' === $functionName ) { |
844 | 844 | |
845 | 845 | $is_unslashed = true; |
846 | - $function_closer = prev( $this->tokens[ $stackPtr ]['nested_parenthesis'] ); |
|
846 | + $function_closer = prev( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ); |
|
847 | 847 | |
848 | 848 | // If there is no other function being used, this value is unsanitized. |
849 | 849 | if ( ! $function_closer ) { |
850 | 850 | return false; |
851 | 851 | } |
852 | 852 | |
853 | - $function_opener = key( $this->tokens[ $stackPtr ]['nested_parenthesis'] ); |
|
854 | - $functionName = $this->tokens[ ( $function_opener - 1 ) ]['content']; |
|
853 | + $function_opener = key( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ); |
|
854 | + $functionName = $this->tokens[ ( $function_opener - 1 ) ][ 'content' ]; |
|
855 | 855 | |
856 | 856 | } else { |
857 | 857 | |
@@ -870,8 +870,8 @@ discard block |
||
870 | 870 | ); |
871 | 871 | |
872 | 872 | // If we're able to resolve the function name, do so. |
873 | - if ( $mapped_function && T_CONSTANT_ENCAPSED_STRING === $this->tokens[ $mapped_function ]['code'] ) { |
|
874 | - $functionName = trim( $this->tokens[ $mapped_function ]['content'], '\'' ); |
|
873 | + if ( $mapped_function && T_CONSTANT_ENCAPSED_STRING === $this->tokens[ $mapped_function ][ 'code' ] ) { |
|
874 | + $functionName = trim( $this->tokens[ $mapped_function ][ 'content' ], '\'' ); |
|
875 | 875 | } |
876 | 876 | } |
877 | 877 | |
@@ -897,7 +897,7 @@ discard block |
||
897 | 897 | 'Missing wp_unslash() before sanitization.', |
898 | 898 | $stackPtr, |
899 | 899 | 'MissingUnslash', |
900 | - array( $this->tokens[ $stackPtr ]['content'] ) |
|
900 | + array( $this->tokens[ $stackPtr ][ 'content' ] ) |
|
901 | 901 | ); |
902 | 902 | } |
903 | 903 | |
@@ -923,13 +923,13 @@ discard block |
||
923 | 923 | ); |
924 | 924 | |
925 | 925 | // If it isn't a bracket, this isn't an array-access. |
926 | - if ( T_OPEN_SQUARE_BRACKET !== $this->tokens[ $open_bracket ]['code'] ) { |
|
926 | + if ( T_OPEN_SQUARE_BRACKET !== $this->tokens[ $open_bracket ][ 'code' ] ) { |
|
927 | 927 | return false; |
928 | 928 | } |
929 | 929 | |
930 | 930 | $key = $this->phpcsFile->getTokensAsString( |
931 | 931 | ( $open_bracket + 1 ) |
932 | - , ( $this->tokens[ $open_bracket ]['bracket_closer'] - $open_bracket - 1 ) |
|
932 | + , ( $this->tokens[ $open_bracket ][ 'bracket_closer' ] - $open_bracket - 1 ) |
|
933 | 933 | ); |
934 | 934 | |
935 | 935 | return trim( $key ); |
@@ -978,16 +978,16 @@ discard block |
||
978 | 978 | */ |
979 | 979 | |
980 | 980 | // If there are no conditions, there's no validation. |
981 | - if ( empty( $this->tokens[ $stackPtr ]['conditions'] ) ) { |
|
981 | + if ( empty( $this->tokens[ $stackPtr ][ 'conditions' ] ) ) { |
|
982 | 982 | return false; |
983 | 983 | } |
984 | 984 | |
985 | - $conditions = $this->tokens[ $stackPtr ]['conditions']; |
|
985 | + $conditions = $this->tokens[ $stackPtr ][ 'conditions' ]; |
|
986 | 986 | end( $conditions ); // Get closest condition. |
987 | 987 | $conditionPtr = key( $conditions ); |
988 | 988 | $condition = $this->tokens[ $conditionPtr ]; |
989 | 989 | |
990 | - if ( ! isset( $condition['parenthesis_opener'] ) ) { |
|
990 | + if ( ! isset( $condition[ 'parenthesis_opener' ] ) ) { |
|
991 | 991 | |
992 | 992 | $this->phpcsFile->addError( |
993 | 993 | 'Possible parse error, condition missing open parenthesis.', |
@@ -998,8 +998,8 @@ discard block |
||
998 | 998 | return false; |
999 | 999 | } |
1000 | 1000 | |
1001 | - $scope_start = $condition['parenthesis_opener']; |
|
1002 | - $scope_end = $condition['parenthesis_closer']; |
|
1001 | + $scope_start = $condition[ 'parenthesis_opener' ]; |
|
1002 | + $scope_end = $condition[ 'parenthesis_closer' ]; |
|
1003 | 1003 | |
1004 | 1004 | } else { |
1005 | 1005 | /* |
@@ -1011,8 +1011,8 @@ discard block |
||
1011 | 1011 | $function = $this->phpcsFile->findPrevious( T_FUNCTION, $stackPtr ); |
1012 | 1012 | |
1013 | 1013 | // If so, we check only within the function, otherwise the whole file. |
1014 | - if ( false !== $function && $stackPtr < $this->tokens[ $function ]['scope_closer'] ) { |
|
1015 | - $scope_start = $this->tokens[ $function ]['scope_opener']; |
|
1014 | + if ( false !== $function && $stackPtr < $this->tokens[ $function ][ 'scope_closer' ] ) { |
|
1015 | + $scope_start = $this->tokens[ $function ][ 'scope_opener' ]; |
|
1016 | 1016 | } else { |
1017 | 1017 | $scope_start = 0; |
1018 | 1018 | } |
@@ -1022,17 +1022,17 @@ discard block |
||
1022 | 1022 | |
1023 | 1023 | for ( $i = ( $scope_start + 1 ); $i < $scope_end; $i++ ) { |
1024 | 1024 | |
1025 | - if ( ! in_array( $this->tokens[ $i ]['code'], array( T_ISSET, T_EMPTY, T_UNSET ), true ) ) { |
|
1025 | + if ( ! in_array( $this->tokens[ $i ][ 'code' ], array( T_ISSET, T_EMPTY, T_UNSET ), true ) ) { |
|
1026 | 1026 | continue; |
1027 | 1027 | } |
1028 | 1028 | |
1029 | 1029 | $issetOpener = $this->phpcsFile->findNext( T_OPEN_PARENTHESIS, $i ); |
1030 | - $issetCloser = $this->tokens[ $issetOpener ]['parenthesis_closer']; |
|
1030 | + $issetCloser = $this->tokens[ $issetOpener ][ 'parenthesis_closer' ]; |
|
1031 | 1031 | |
1032 | 1032 | // Look for this variable. We purposely stomp $i from the parent loop. |
1033 | 1033 | for ( $i = ( $issetOpener + 1 ); $i < $issetCloser; $i++ ) { |
1034 | 1034 | |
1035 | - if ( T_VARIABLE !== $this->tokens[ $i ]['code'] ) { |
|
1035 | + if ( T_VARIABLE !== $this->tokens[ $i ][ 'code' ] ) { |
|
1036 | 1036 | continue; |
1037 | 1037 | } |
1038 | 1038 | |
@@ -1065,12 +1065,12 @@ discard block |
||
1065 | 1065 | protected function is_comparison( $stackPtr ) { |
1066 | 1066 | |
1067 | 1067 | // We first check if this is a switch statement (switch ( $var )). |
1068 | - if ( isset( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) ) { |
|
1069 | - $close_parenthesis = end( $this->tokens[ $stackPtr ]['nested_parenthesis'] ); |
|
1068 | + if ( isset( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) ) { |
|
1069 | + $close_parenthesis = end( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ); |
|
1070 | 1070 | |
1071 | 1071 | if ( |
1072 | - isset( $this->tokens[ $close_parenthesis ]['parenthesis_owner'] ) |
|
1073 | - && T_SWITCH === $this->tokens[ $this->tokens[ $close_parenthesis ]['parenthesis_owner'] ]['code'] |
|
1072 | + isset( $this->tokens[ $close_parenthesis ][ 'parenthesis_owner' ] ) |
|
1073 | + && T_SWITCH === $this->tokens[ $this->tokens[ $close_parenthesis ][ 'parenthesis_owner' ] ][ 'code' ] |
|
1074 | 1074 | ) { |
1075 | 1075 | return true; |
1076 | 1076 | } |
@@ -1085,7 +1085,7 @@ discard block |
||
1085 | 1085 | true |
1086 | 1086 | ); |
1087 | 1087 | |
1088 | - if ( in_array( $this->tokens[ $previous_token ]['code'], PHP_CodeSniffer_Tokens::$comparisonTokens, true ) ) { |
|
1088 | + if ( in_array( $this->tokens[ $previous_token ][ 'code' ], PHP_CodeSniffer_Tokens::$comparisonTokens, true ) ) { |
|
1089 | 1089 | return true; |
1090 | 1090 | } |
1091 | 1091 | |
@@ -1098,17 +1098,17 @@ discard block |
||
1098 | 1098 | ); |
1099 | 1099 | |
1100 | 1100 | // This might be an opening square bracket in the case of arrays ($var['a']). |
1101 | - while ( T_OPEN_SQUARE_BRACKET === $this->tokens[ $next_token ]['code'] ) { |
|
1101 | + while ( T_OPEN_SQUARE_BRACKET === $this->tokens[ $next_token ][ 'code' ] ) { |
|
1102 | 1102 | |
1103 | 1103 | $next_token = $this->phpcsFile->findNext( |
1104 | 1104 | PHP_CodeSniffer_Tokens::$emptyTokens, |
1105 | - ( $this->tokens[ $next_token ]['bracket_closer'] + 1 ), |
|
1105 | + ( $this->tokens[ $next_token ][ 'bracket_closer' ] + 1 ), |
|
1106 | 1106 | null, |
1107 | 1107 | true |
1108 | 1108 | ); |
1109 | 1109 | } |
1110 | 1110 | |
1111 | - if ( in_array( $this->tokens[ $next_token ]['code'], PHP_CodeSniffer_Tokens::$comparisonTokens, true ) ) { |
|
1111 | + if ( in_array( $this->tokens[ $next_token ][ 'code' ], PHP_CodeSniffer_Tokens::$comparisonTokens, true ) ) { |
|
1112 | 1112 | return true; |
1113 | 1113 | } |
1114 | 1114 | |
@@ -1138,7 +1138,7 @@ discard block |
||
1138 | 1138 | // USE keywords inside closures. |
1139 | 1139 | $next = $this->phpcsFile->findNext( T_WHITESPACE, ( $stackPtr + 1 ), null, true ); |
1140 | 1140 | |
1141 | - if ( T_OPEN_PARENTHESIS === $this->tokens[ $next ]['code'] ) { |
|
1141 | + if ( T_OPEN_PARENTHESIS === $this->tokens[ $next ][ 'code' ] ) { |
|
1142 | 1142 | return 'closure'; |
1143 | 1143 | } |
1144 | 1144 | |
@@ -1166,8 +1166,8 @@ discard block |
||
1166 | 1166 | $variables = array(); |
1167 | 1167 | if ( preg_match_all( '/(?P<backslashes>\\\\*)\$(?P<symbol>\w+)/', $string, $match_sets, PREG_SET_ORDER ) ) { |
1168 | 1168 | foreach ( $match_sets as $matches ) { |
1169 | - if ( ( strlen( $matches['backslashes'] ) % 2 ) === 0 ) { |
|
1170 | - $variables[] = $matches['symbol']; |
|
1169 | + if ( ( strlen( $matches[ 'backslashes' ] ) % 2 ) === 0 ) { |
|
1170 | + $variables[ ] = $matches[ 'symbol' ]; |
|
1171 | 1171 | } |
1172 | 1172 | } |
1173 | 1173 | } |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | $token = $tokens[ $stackPtr ]; |
90 | 90 | $classname = ''; |
91 | 91 | |
92 | - if ( in_array( $token['code'], array( T_NEW, T_EXTENDS, T_IMPLEMENTS ), true ) ) { |
|
93 | - if ( T_NEW === $token['code'] ) { |
|
92 | + if ( in_array( $token[ 'code' ], array( T_NEW, T_EXTENDS, T_IMPLEMENTS ), true ) ) { |
|
93 | + if ( T_NEW === $token[ 'code' ] ) { |
|
94 | 94 | $nameEnd = ( $phpcsFile->findNext( array( T_OPEN_PARENTHESIS, T_WHITESPACE, T_SEMICOLON, T_OBJECT_OPERATOR ), ( $stackPtr + 2 ) ) - 1 ); |
95 | 95 | } else { |
96 | 96 | $nameEnd = ( $phpcsFile->findNext( array( T_CLOSE_CURLY_BRACKET, T_WHITESPACE ), ( $stackPtr + 2 ) ) - 1 ); |
@@ -99,18 +99,18 @@ discard block |
||
99 | 99 | $length = ( $nameEnd - ( $stackPtr + 1 ) ); |
100 | 100 | $classname = $phpcsFile->getTokensAsString( ( $stackPtr + 2 ), $length ); |
101 | 101 | |
102 | - if ( T_NS_SEPARATOR !== $tokens[ ( $stackPtr + 2 ) ]['code'] ) { |
|
102 | + if ( T_NS_SEPARATOR !== $tokens[ ( $stackPtr + 2 ) ][ 'code' ] ) { |
|
103 | 103 | $classname = $this->get_namespaced_classname( $classname, $phpcsFile, $tokens, ( $stackPtr - 1 ) ); |
104 | 104 | } |
105 | 105 | } |
106 | 106 | |
107 | - if ( T_DOUBLE_COLON === $token['code'] ) { |
|
107 | + if ( T_DOUBLE_COLON === $token[ 'code' ] ) { |
|
108 | 108 | $nameEnd = $phpcsFile->findPrevious( array( T_STRING ), ( $stackPtr - 1 ) ); |
109 | 109 | $nameStart = ( $phpcsFile->findPrevious( array( T_STRING, T_NS_SEPARATOR, T_NAMESPACE ), ( $nameEnd - 1 ), null, true, null, true ) + 1 ); |
110 | - $length = ( $nameEnd - ( $nameStart - 1) ); |
|
110 | + $length = ( $nameEnd - ( $nameStart - 1 ) ); |
|
111 | 111 | $classname = $phpcsFile->getTokensAsString( $nameStart, $length ); |
112 | 112 | |
113 | - if ( T_NS_SEPARATOR !== $tokens[ $nameStart ]['code'] ) { |
|
113 | + if ( T_NS_SEPARATOR !== $tokens[ $nameStart ][ 'code' ] ) { |
|
114 | 114 | $classname = $this->get_namespaced_classname( $classname, $phpcsFile, $tokens, ( $nameStart - 1 ) ); |
115 | 115 | } |
116 | 116 | } |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | return; |
126 | 126 | } |
127 | 127 | |
128 | - $exclude = explode( ',', $this->exclude ); |
|
128 | + $exclude = explode( ',', $this->exclude ); |
|
129 | 129 | |
130 | 130 | foreach ( $this->groups as $groupName => $group ) { |
131 | 131 | |
@@ -133,11 +133,11 @@ discard block |
||
133 | 133 | continue; |
134 | 134 | } |
135 | 135 | |
136 | - if ( preg_match( $group['regex'], $classname ) < 1 ) { |
|
136 | + if ( preg_match( $group[ 'regex' ], $classname ) < 1 ) { |
|
137 | 137 | continue; |
138 | 138 | } |
139 | 139 | |
140 | - if ( 'warning' === $group['type'] ) { |
|
140 | + if ( 'warning' === $group[ 'type' ] ) { |
|
141 | 141 | $addWhat = array( $phpcsFile, 'addWarning' ); |
142 | 142 | } else { |
143 | 143 | $addWhat = array( $phpcsFile, 'addError' ); |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | |
146 | 146 | call_user_func( |
147 | 147 | $addWhat, |
148 | - $group['message'], |
|
148 | + $group[ 'message' ], |
|
149 | 149 | $stackPtr, |
150 | 150 | $groupName, |
151 | 151 | array( $classname ) |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | */ |
170 | 170 | protected function prepare_name_for_regex( $classname ) { |
171 | 171 | $classname = trim( $classname, '\\' ); // Make sure all classnames have a \ prefix, but only one. |
172 | - $classname = str_replace( array( '.*', '*' ) , '#', $classname ); // Replace wildcards with placeholder. |
|
172 | + $classname = str_replace( array( '.*', '*' ), '#', $classname ); // Replace wildcards with placeholder. |
|
173 | 173 | $classname = preg_quote( $classname, '`' ); |
174 | 174 | $classname = str_replace( '#', '.*', $classname ); // Replace placeholder with regex wildcard. |
175 | 175 | |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | */ |
188 | 188 | protected function get_namespaced_classname( $classname, PHP_CodeSniffer_File $phpcsFile, $tokens, $search_from ) { |
189 | 189 | // Don't do anything if this is already a fully qualified classname. |
190 | - if ( empty( $classname ) || '\\' === $classname[0] ) { |
|
190 | + if ( empty( $classname ) || '\\' === $classname[ 0 ] ) { |
|
191 | 191 | return $classname; |
192 | 192 | } |
193 | 193 | |
@@ -225,10 +225,10 @@ discard block |
||
225 | 225 | protected function determine_namespace( PHP_CodeSniffer_File $phpcsFile, $tokens, $search_from ) { |
226 | 226 | $namespace = ''; |
227 | 227 | |
228 | - if ( ! empty( $tokens[ $search_from ]['conditions'] ) ) { |
|
228 | + if ( ! empty( $tokens[ $search_from ][ 'conditions' ] ) ) { |
|
229 | 229 | // Scoped namespace {}. |
230 | - foreach ( $tokens[ $search_from ]['conditions'] as $pointer => $type ) { |
|
231 | - if ( T_NAMESPACE === $type && $tokens[ $pointer ]['scope_closer'] > $search_from ) { |
|
230 | + foreach ( $tokens[ $search_from ][ 'conditions' ] as $pointer => $type ) { |
|
231 | + if ( T_NAMESPACE === $type && $tokens[ $pointer ][ 'scope_closer' ] > $search_from ) { |
|
232 | 232 | $namespace = $this->get_namespace_name( $phpcsFile, $tokens, $pointer ); |
233 | 233 | } |
234 | 234 | break; // We only need to check the highest level condition. |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | // Let's see if we can find a file namespace instead. |
238 | 238 | $first = $phpcsFile->findNext( array( T_NAMESPACE ), 0, $search_from ); |
239 | 239 | |
240 | - if ( empty( $tokens[ $first ]['scope_condition'] ) ) { |
|
240 | + if ( empty( $tokens[ $first ][ 'scope_condition' ] ) ) { |
|
241 | 241 | $namespace = $this->get_namespace_name( $phpcsFile, $tokens, $first ); |
242 | 242 | } |
243 | 243 | } |
@@ -93,10 +93,10 @@ discard block |
||
93 | 93 | } |
94 | 94 | |
95 | 95 | // Check if it is a function not a variable. |
96 | - if ( in_array( $token['code'], array( T_OBJECT_OPERATOR, T_DOUBLE_COLON ), true ) ) { // This only works for object vars and array members. |
|
96 | + if ( in_array( $token[ 'code' ], array( T_OBJECT_OPERATOR, T_DOUBLE_COLON ), true ) ) { // This only works for object vars and array members. |
|
97 | 97 | $method = $phpcsFile->findNext( T_WHITESPACE, ( $stackPtr + 1 ), null, true ); |
98 | 98 | $possible_parenthesis = $phpcsFile->findNext( T_WHITESPACE, ( $method + 1 ), null, true ); |
99 | - if ( T_OPEN_PARENTHESIS === $tokens[ $possible_parenthesis ]['code'] ) { |
|
99 | + if ( T_OPEN_PARENTHESIS === $tokens[ $possible_parenthesis ][ 'code' ] ) { |
|
100 | 100 | return; // So .. it is a function after all ! |
101 | 101 | } |
102 | 102 | } |
@@ -110,25 +110,25 @@ discard block |
||
110 | 110 | $patterns = array(); |
111 | 111 | |
112 | 112 | // Simple variable. |
113 | - if ( in_array( $token['code'], array( T_VARIABLE, T_DOUBLE_QUOTED_STRING ), true ) && ! empty( $group['variables'] ) ) { |
|
114 | - $patterns = array_merge( $patterns, $group['variables'] ); |
|
115 | - $var = $token['content']; |
|
113 | + if ( in_array( $token[ 'code' ], array( T_VARIABLE, T_DOUBLE_QUOTED_STRING ), true ) && ! empty( $group[ 'variables' ] ) ) { |
|
114 | + $patterns = array_merge( $patterns, $group[ 'variables' ] ); |
|
115 | + $var = $token[ 'content' ]; |
|
116 | 116 | |
117 | - } elseif ( in_array( $token['code'], array( T_OBJECT_OPERATOR, T_DOUBLE_COLON, T_DOUBLE_QUOTED_STRING ), true ) && ! empty( $group['object_vars'] ) ) { |
|
117 | + } elseif ( in_array( $token[ 'code' ], array( T_OBJECT_OPERATOR, T_DOUBLE_COLON, T_DOUBLE_QUOTED_STRING ), true ) && ! empty( $group[ 'object_vars' ] ) ) { |
|
118 | 118 | // Object var, ex: $foo->bar / $foo::bar / Foo::bar / Foo::$bar . |
119 | - $patterns = array_merge( $patterns, $group['object_vars'] ); |
|
119 | + $patterns = array_merge( $patterns, $group[ 'object_vars' ] ); |
|
120 | 120 | |
121 | 121 | $owner = $phpcsFile->findPrevious( array( T_VARIABLE, T_STRING ), $stackPtr ); |
122 | 122 | $child = $phpcsFile->findNext( array( T_STRING, T_VAR, T_VARIABLE ), $stackPtr ); |
123 | - $var = implode( '', array( $tokens[ $owner ]['content'], $token['content'], $tokens[ $child ]['content'] ) ); |
|
123 | + $var = implode( '', array( $tokens[ $owner ][ 'content' ], $token[ 'content' ], $tokens[ $child ][ 'content' ] ) ); |
|
124 | 124 | |
125 | - } elseif ( in_array( $token['code'], array( T_OPEN_SQUARE_BRACKET, T_DOUBLE_QUOTED_STRING ), true ) && ! empty( $group['array_members'] ) ) { |
|
125 | + } elseif ( in_array( $token[ 'code' ], array( T_OPEN_SQUARE_BRACKET, T_DOUBLE_QUOTED_STRING ), true ) && ! empty( $group[ 'array_members' ] ) ) { |
|
126 | 126 | // Array members. |
127 | - $patterns = array_merge( $patterns, $group['array_members'] ); |
|
127 | + $patterns = array_merge( $patterns, $group[ 'array_members' ] ); |
|
128 | 128 | |
129 | 129 | $owner = $phpcsFile->findPrevious( array( T_VARIABLE ), $stackPtr ); |
130 | - $inside = $phpcsFile->getTokensAsString( $stackPtr, ( $token['bracket_closer'] - $stackPtr + 1 ) ); |
|
131 | - $var = implode( '', array( $tokens[ $owner ]['content'], $inside ) ); |
|
130 | + $inside = $phpcsFile->getTokensAsString( $stackPtr, ( $token[ 'bracket_closer' ] - $stackPtr + 1 ) ); |
|
131 | + $var = implode( '', array( $tokens[ $owner ][ 'content' ], $inside ) ); |
|
132 | 132 | } else { |
133 | 133 | continue; |
134 | 134 | } |
@@ -139,17 +139,17 @@ discard block |
||
139 | 139 | |
140 | 140 | $patterns = array_map( array( $this, 'test_patterns' ), $patterns ); |
141 | 141 | $pattern = implode( '|', $patterns ); |
142 | - $delim = ( T_OPEN_SQUARE_BRACKET !== $token['code'] ) ? '\b' : ''; |
|
142 | + $delim = ( T_OPEN_SQUARE_BRACKET !== $token[ 'code' ] ) ? '\b' : ''; |
|
143 | 143 | |
144 | - if ( T_DOUBLE_QUOTED_STRING === $token['code'] ) { |
|
145 | - $var = $token['content']; |
|
144 | + if ( T_DOUBLE_QUOTED_STRING === $token[ 'code' ] ) { |
|
145 | + $var = $token[ 'content' ]; |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | if ( preg_match( '#(' . $pattern . ')' . $delim . '#', $var, $match ) !== 1 ) { |
149 | 149 | continue; |
150 | 150 | } |
151 | 151 | |
152 | - if ( 'warning' === $group['type'] ) { |
|
152 | + if ( 'warning' === $group[ 'type' ] ) { |
|
153 | 153 | $addWhat = array( $phpcsFile, 'addWarning' ); |
154 | 154 | } else { |
155 | 155 | $addWhat = array( $phpcsFile, 'addError' ); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | |
158 | 158 | call_user_func( |
159 | 159 | $addWhat, |
160 | - $group['message'], |
|
160 | + $group[ 'message' ], |
|
161 | 161 | $stackPtr, |
162 | 162 | $groupName, |
163 | 163 | array( $var ) |
@@ -93,7 +93,8 @@ |
||
93 | 93 | } |
94 | 94 | |
95 | 95 | // Check if it is a function not a variable. |
96 | - if ( in_array( $token['code'], array( T_OBJECT_OPERATOR, T_DOUBLE_COLON ), true ) ) { // This only works for object vars and array members. |
|
96 | + if ( in_array( $token['code'], array( T_OBJECT_OPERATOR, T_DOUBLE_COLON ), true ) ) { |
|
97 | +// This only works for object vars and array members. |
|
97 | 98 | $method = $phpcsFile->findNext( T_WHITESPACE, ( $stackPtr + 1 ), null, true ); |
98 | 99 | $possible_parenthesis = $phpcsFile->findNext( T_WHITESPACE, ( $method + 1 ), null, true ); |
99 | 100 | if ( T_OPEN_PARENTHESIS === $tokens[ $possible_parenthesis ]['code'] ) { |
@@ -62,13 +62,13 @@ discard block |
||
62 | 62 | public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { |
63 | 63 | $tokens = $phpcsFile->getTokens(); |
64 | 64 | $openTag = $tokens[ $stackPtr ]; |
65 | - $content = $openTag['content']; |
|
65 | + $content = $openTag[ 'content' ]; |
|
66 | 66 | |
67 | 67 | if ( '' === trim( $content ) ) { |
68 | 68 | return; |
69 | 69 | } |
70 | 70 | |
71 | - if ( T_OPEN_TAG === $openTag['code'] ) { |
|
71 | + if ( T_OPEN_TAG === $openTag[ 'code' ] ) { |
|
72 | 72 | |
73 | 73 | if ( '<%' === $content ) { |
74 | 74 | $error = 'ASP style opening tag used; expected "<?php" but found "%s"'; |
@@ -97,10 +97,10 @@ discard block |
||
97 | 97 | return; |
98 | 98 | } |
99 | 99 | |
100 | - if ( T_OPEN_TAG_WITH_ECHO === $openTag['code'] && '<%=' === $content ) { |
|
100 | + if ( T_OPEN_TAG_WITH_ECHO === $openTag[ 'code' ] && '<%=' === $content ) { |
|
101 | 101 | $error = 'ASP style opening tag used with echo; expected "<?php echo %s ..." but found "%s %s ..."'; |
102 | 102 | $nextVar = $phpcsFile->findNext( T_WHITESPACE, ( $stackPtr + 1 ), null, true ); |
103 | - $snippet = $this->get_snippet( $tokens[ $nextVar ]['content'] ); |
|
103 | + $snippet = $this->get_snippet( $tokens[ $nextVar ][ 'content' ] ); |
|
104 | 104 | $data = array( |
105 | 105 | $snippet, |
106 | 106 | $content, |
@@ -122,17 +122,17 @@ discard block |
||
122 | 122 | } |
123 | 123 | |
124 | 124 | // Account for incorrect script open tags. The "(?:<s)?" in the regex is to work-around a bug in PHP 5.2. |
125 | - if ( T_INLINE_HTML === $openTag['code'] && 1 === preg_match( '`((?:<s)?cript (?:[^>]+)?language=[\'"]?php[\'"]?(?:[^>]+)?>)`i', $content, $match ) ) { |
|
125 | + if ( T_INLINE_HTML === $openTag[ 'code' ] && 1 === preg_match( '`((?:<s)?cript (?:[^>]+)?language=[\'"]?php[\'"]?(?:[^>]+)?>)`i', $content, $match ) ) { |
|
126 | 126 | $error = 'Script style opening tag used; expected "<?php" but found "%s"'; |
127 | - $snippet = $this->get_snippet( $content, $match[1] ); |
|
128 | - $data = array( $match[1] . $snippet ); |
|
127 | + $snippet = $this->get_snippet( $content, $match[ 1 ] ); |
|
128 | + $data = array( $match[ 1 ] . $snippet ); |
|
129 | 129 | |
130 | 130 | $phpcsFile->addError( $error, $stackPtr, 'ScriptOpenTagFound', $data ); |
131 | 131 | |
132 | 132 | return; |
133 | 133 | } |
134 | 134 | |
135 | - if ( T_INLINE_HTML === $openTag['code'] && false === $this->asp_tags ) { |
|
135 | + if ( T_INLINE_HTML === $openTag[ 'code' ] && false === $this->asp_tags ) { |
|
136 | 136 | if ( false !== strpos( $content, '<%=' ) ) { |
137 | 137 | $error = 'Possible use of ASP style short opening tags detected. Needs manual inspection. Found: %s'; |
138 | 138 | $snippet = $this->get_snippet( $content, '<%=' ); |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | private function find_closing_tag( PHP_CodeSniffer_File $phpcsFile, $tokens, $stackPtr, $content ) { |
190 | 190 | $closer = $phpcsFile->findNext( T_CLOSE_TAG, ( $stackPtr + 1 ) ); |
191 | 191 | |
192 | - if ( false !== $closer && trim( $tokens[ $closer ]['content'] ) === $content ) { |
|
192 | + if ( false !== $closer && trim( $tokens[ $closer ][ 'content' ] ) === $content ) { |
|
193 | 193 | return $closer; |
194 | 194 | } |
195 | 195 | |
@@ -211,13 +211,13 @@ discard block |
||
211 | 211 | if ( true === $echo ) { |
212 | 212 | $open_replacement .= ' echo'; |
213 | 213 | } |
214 | - if ( T_WHITESPACE !== $tokens[ ( $open_tag_pointer + 1 ) ]['code'] ) { |
|
214 | + if ( T_WHITESPACE !== $tokens[ ( $open_tag_pointer + 1 ) ][ 'code' ] ) { |
|
215 | 215 | $open_replacement .= ' '; |
216 | 216 | } |
217 | 217 | |
218 | 218 | // Make sure we don't remove any line breaks after the closing tag. |
219 | - $regex = '`' . preg_quote( trim( $tokens[ $close_tag_pointer ]['content'] ) ) . '`'; |
|
220 | - $close_replacement = preg_replace( $regex, '?>', $tokens[ $close_tag_pointer ]['content'] ); |
|
219 | + $regex = '`' . preg_quote( trim( $tokens[ $close_tag_pointer ][ 'content' ] ) ) . '`'; |
|
220 | + $close_replacement = preg_replace( $regex, '?>', $tokens[ $close_tag_pointer ][ 'content' ] ); |
|
221 | 221 | |
222 | 222 | $phpcsFile->fixer->beginChangeset(); |
223 | 223 | $phpcsFile->fixer->replaceToken( $open_tag_pointer, $open_replacement ); |
@@ -45,11 +45,11 @@ |
||
45 | 45 | $tokens = $phpcsFile->getTokens(); |
46 | 46 | $token = $tokens[ $stackPtr ]; |
47 | 47 | |
48 | - if ( preg_match( '#rel=[\'"]?stylesheet[\'"]?#', $token['content'] ) > 0 ) { |
|
48 | + if ( preg_match( '#rel=[\'"]?stylesheet[\'"]?#', $token[ 'content' ] ) > 0 ) { |
|
49 | 49 | $phpcsFile->addError( 'Stylesheets must be registered/enqueued via wp_enqueue_style', $stackPtr, 'NonEnqueuedStylesheet' ); |
50 | 50 | } |
51 | 51 | |
52 | - if ( preg_match( '#<script[^>]*(?<=src=)#', $token['content'] ) > 0 ) { |
|
52 | + if ( preg_match( '#<script[^>]*(?<=src=)#', $token[ 'content' ] ) > 0 ) { |
|
53 | 53 | $phpcsFile->addError( 'Scripts must be registered/enqueued via wp_enqueue_script', $stackPtr, 'NonEnqueuedScript' ); |
54 | 54 | } |
55 | 55 |
@@ -145,8 +145,8 @@ |
||
145 | 145 | for ( $nextToken = ( $stackPtr + 1 ); $nextToken < $arrayEnd; $nextToken++ ) { |
146 | 146 | // Skip bracketed statements, like function calls. |
147 | 147 | if ( T_OPEN_PARENTHESIS === $tokens[ $nextToken ]['code'] |
148 | - && ( ! isset( $tokens[ $nextToken ]['parenthesis_owner'] ) |
|
149 | - || $tokens[ $nextToken ]['parenthesis_owner'] !== $stackPtr ) |
|
148 | + && ( ! isset( $tokens[ $nextToken ]['parenthesis_owner'] ) |
|
149 | + || $tokens[ $nextToken ]['parenthesis_owner'] !== $stackPtr ) |
|
150 | 150 | ) { |
151 | 151 | $nextToken = $tokens[ $nextToken ]['parenthesis_closer']; |
152 | 152 | continue; |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | $tokens = $phpcsFile->getTokens(); |
60 | 60 | |
61 | 61 | // Check that there is a single space after the array opener. |
62 | - if ( T_WHITESPACE !== $tokens[ ( $arrayStart + 1 ) ]['code'] ) { |
|
62 | + if ( T_WHITESPACE !== $tokens[ ( $arrayStart + 1 ) ][ 'code' ] ) { |
|
63 | 63 | |
64 | 64 | $warning = 'Missing space after array opener.'; |
65 | 65 | $fix = $phpcsFile->addFixableError( $warning, $arrayStart, 'NoSpaceAfterOpenParenthesis' ); |
@@ -67,13 +67,13 @@ discard block |
||
67 | 67 | if ( true === $fix ) { |
68 | 68 | $phpcsFile->fixer->addContent( $arrayStart, ' ' ); |
69 | 69 | } |
70 | - } elseif ( ' ' !== $tokens[ ( $arrayStart + 1 ) ]['content'] ) { |
|
70 | + } elseif ( ' ' !== $tokens[ ( $arrayStart + 1 ) ][ 'content' ] ) { |
|
71 | 71 | |
72 | 72 | $fix = $phpcsFile->addFixableError( |
73 | 73 | 'Expected 1 space after array opener, found %s.', |
74 | 74 | $arrayStart, |
75 | 75 | 'SpaceAfterArrayOpener', |
76 | - strlen( $tokens[ ( $arrayStart + 1 ) ]['content'] ) |
|
76 | + strlen( $tokens[ ( $arrayStart + 1 ) ][ 'content' ] ) |
|
77 | 77 | ); |
78 | 78 | |
79 | 79 | if ( true === $fix ) { |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | } |
82 | 82 | } |
83 | 83 | |
84 | - if ( T_WHITESPACE !== $tokens[ ( $arrayEnd - 1 ) ]['code'] ) { |
|
84 | + if ( T_WHITESPACE !== $tokens[ ( $arrayEnd - 1 ) ][ 'code' ] ) { |
|
85 | 85 | |
86 | 86 | $warning = 'Missing space before array closer.'; |
87 | 87 | $fix = $phpcsFile->addFixableError( $warning, $arrayEnd, 'NoSpaceAfterOpenParenthesis' ); |
@@ -89,13 +89,13 @@ discard block |
||
89 | 89 | if ( true === $fix ) { |
90 | 90 | $phpcsFile->fixer->addContentBefore( $arrayEnd, ' ' ); |
91 | 91 | } |
92 | - } elseif ( ' ' !== $tokens[ ( $arrayEnd - 1 ) ]['content'] ) { |
|
92 | + } elseif ( ' ' !== $tokens[ ( $arrayEnd - 1 ) ][ 'content' ] ) { |
|
93 | 93 | |
94 | 94 | $fix = $phpcsFile->addFixableError( |
95 | 95 | 'Expected 1 space before array closer, found %s.', |
96 | 96 | $arrayEnd, |
97 | 97 | 'SpaceAfterArrayCloser', |
98 | - strlen( $tokens[ ( $arrayEnd - 1 ) ]['content'] ) |
|
98 | + strlen( $tokens[ ( $arrayEnd - 1 ) ][ 'content' ] ) |
|
99 | 99 | ); |
100 | 100 | |
101 | 101 | if ( true === $fix ) { |
@@ -117,11 +117,11 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function processMultiLineArray( PHP_CodeSniffer_File $phpcsFile, $stackPtr, $arrayStart, $arrayEnd ) { |
119 | 119 | $tokens = $phpcsFile->getTokens(); |
120 | - $keywordStart = $tokens[ $stackPtr ]['column']; |
|
120 | + $keywordStart = $tokens[ $stackPtr ][ 'column' ]; |
|
121 | 121 | |
122 | 122 | // Check the closing bracket is on a new line. |
123 | 123 | $lastContent = $phpcsFile->findPrevious( T_WHITESPACE, ( $arrayEnd - 1 ), $arrayStart, true ); |
124 | - if ( $tokens[ $lastContent ]['line'] === $tokens[ $arrayEnd ]['line'] ) { |
|
124 | + if ( $tokens[ $lastContent ][ 'line' ] === $tokens[ $arrayEnd ][ 'line' ] ) { |
|
125 | 125 | $error = 'Closing parenthesis of array declaration must be on a new line'; |
126 | 126 | $fix = $phpcsFile->addFixableError( $error, $arrayEnd, 'CloseBraceNewLine' ); |
127 | 127 | if ( true === $fix ) { |
@@ -135,8 +135,8 @@ discard block |
||
135 | 135 | $indices = array(); |
136 | 136 | $maxLength = 0; |
137 | 137 | |
138 | - if ( T_ARRAY === $tokens[ $stackPtr ]['code'] ) { |
|
139 | - $lastToken = $tokens[ $stackPtr ]['parenthesis_opener']; |
|
138 | + if ( T_ARRAY === $tokens[ $stackPtr ][ 'code' ] ) { |
|
139 | + $lastToken = $tokens[ $stackPtr ][ 'parenthesis_opener' ]; |
|
140 | 140 | } else { |
141 | 141 | $lastToken = $stackPtr; |
142 | 142 | } |
@@ -144,24 +144,24 @@ discard block |
||
144 | 144 | // Find all the double arrows that reside in this scope. |
145 | 145 | for ( $nextToken = ( $stackPtr + 1 ); $nextToken < $arrayEnd; $nextToken++ ) { |
146 | 146 | // Skip bracketed statements, like function calls. |
147 | - if ( T_OPEN_PARENTHESIS === $tokens[ $nextToken ]['code'] |
|
148 | - && ( ! isset( $tokens[ $nextToken ]['parenthesis_owner'] ) |
|
149 | - || $tokens[ $nextToken ]['parenthesis_owner'] !== $stackPtr ) |
|
147 | + if ( T_OPEN_PARENTHESIS === $tokens[ $nextToken ][ 'code' ] |
|
148 | + && ( ! isset( $tokens[ $nextToken ][ 'parenthesis_owner' ] ) |
|
149 | + || $tokens[ $nextToken ][ 'parenthesis_owner' ] !== $stackPtr ) |
|
150 | 150 | ) { |
151 | - $nextToken = $tokens[ $nextToken ]['parenthesis_closer']; |
|
151 | + $nextToken = $tokens[ $nextToken ][ 'parenthesis_closer' ]; |
|
152 | 152 | continue; |
153 | 153 | } |
154 | 154 | |
155 | - if ( T_ARRAY === $tokens[ $nextToken ]['code'] ) { |
|
155 | + if ( T_ARRAY === $tokens[ $nextToken ][ 'code' ] ) { |
|
156 | 156 | // Let subsequent calls of this test handle nested arrays. |
157 | - if ( T_DOUBLE_ARROW !== $tokens[ $lastToken ]['code'] ) { |
|
158 | - $indices[] = array( 'value' => $nextToken ); |
|
157 | + if ( T_DOUBLE_ARROW !== $tokens[ $lastToken ][ 'code' ] ) { |
|
158 | + $indices[ ] = array( 'value' => $nextToken ); |
|
159 | 159 | $lastToken = $nextToken; |
160 | 160 | } |
161 | 161 | |
162 | - $nextToken = $tokens[ $tokens[ $nextToken ]['parenthesis_opener'] ]['parenthesis_closer']; |
|
162 | + $nextToken = $tokens[ $tokens[ $nextToken ][ 'parenthesis_opener' ] ][ 'parenthesis_closer' ]; |
|
163 | 163 | $nextToken = $phpcsFile->findNext( T_WHITESPACE, ( $nextToken + 1 ), null, true ); |
164 | - if ( T_COMMA !== $tokens[ $nextToken ]['code'] ) { |
|
164 | + if ( T_COMMA !== $tokens[ $nextToken ][ 'code' ] ) { |
|
165 | 165 | $nextToken--; |
166 | 166 | } else { |
167 | 167 | $lastToken = $nextToken; |
@@ -170,16 +170,16 @@ discard block |
||
170 | 170 | continue; |
171 | 171 | } |
172 | 172 | |
173 | - if ( T_OPEN_SHORT_ARRAY === $tokens[ $nextToken ]['code'] ) { |
|
173 | + if ( T_OPEN_SHORT_ARRAY === $tokens[ $nextToken ][ 'code' ] ) { |
|
174 | 174 | // Let subsequent calls of this test handle nested arrays. |
175 | - if ( T_DOUBLE_ARROW !== $tokens[ $lastToken ]['code'] ) { |
|
176 | - $indices[] = array( 'value' => $nextToken ); |
|
175 | + if ( T_DOUBLE_ARROW !== $tokens[ $lastToken ][ 'code' ] ) { |
|
176 | + $indices[ ] = array( 'value' => $nextToken ); |
|
177 | 177 | $lastToken = $nextToken; |
178 | 178 | } |
179 | 179 | |
180 | - $nextToken = $tokens[ $nextToken ]['bracket_closer']; |
|
180 | + $nextToken = $tokens[ $nextToken ][ 'bracket_closer' ]; |
|
181 | 181 | $nextToken = $phpcsFile->findNext( T_WHITESPACE, ( $nextToken + 1 ), null, true ); |
182 | - if ( T_COMMA !== $tokens[ $nextToken ]['code'] ) { |
|
182 | + if ( T_COMMA !== $tokens[ $nextToken ][ 'code' ] ) { |
|
183 | 183 | $nextToken--; |
184 | 184 | } else { |
185 | 185 | $lastToken = $nextToken; |
@@ -188,15 +188,15 @@ discard block |
||
188 | 188 | continue; |
189 | 189 | } |
190 | 190 | |
191 | - if ( T_CLOSURE === $tokens[ $nextToken ]['code'] ) { |
|
192 | - if ( T_DOUBLE_ARROW !== $tokens[ $lastToken ]['code'] ) { |
|
193 | - $indices[] = array( 'value' => $nextToken ); |
|
191 | + if ( T_CLOSURE === $tokens[ $nextToken ][ 'code' ] ) { |
|
192 | + if ( T_DOUBLE_ARROW !== $tokens[ $lastToken ][ 'code' ] ) { |
|
193 | + $indices[ ] = array( 'value' => $nextToken ); |
|
194 | 194 | $lastToken = $nextToken; |
195 | 195 | } |
196 | 196 | |
197 | - $nextToken = $tokens[ $nextToken ]['scope_closer']; |
|
197 | + $nextToken = $tokens[ $nextToken ][ 'scope_closer' ]; |
|
198 | 198 | $nextToken = $phpcsFile->findNext( T_WHITESPACE, ( $nextToken + 1 ), null, true ); |
199 | - if ( T_COMMA !== $tokens[ $nextToken ]['code'] ) { |
|
199 | + if ( T_COMMA !== $tokens[ $nextToken ][ 'code' ] ) { |
|
200 | 200 | $nextToken--; |
201 | 201 | } else { |
202 | 202 | $lastToken = $nextToken; |
@@ -205,22 +205,22 @@ discard block |
||
205 | 205 | continue; |
206 | 206 | } |
207 | 207 | |
208 | - if ( T_DOUBLE_ARROW !== $tokens[ $nextToken ]['code'] && T_COMMA !== $tokens[ $nextToken ]['code'] ) { |
|
208 | + if ( T_DOUBLE_ARROW !== $tokens[ $nextToken ][ 'code' ] && T_COMMA !== $tokens[ $nextToken ][ 'code' ] ) { |
|
209 | 209 | continue; |
210 | 210 | } |
211 | 211 | |
212 | 212 | $currentEntry = array(); |
213 | 213 | |
214 | - if ( T_COMMA === $tokens[ $nextToken ]['code'] ) { |
|
214 | + if ( T_COMMA === $tokens[ $nextToken ][ 'code' ] ) { |
|
215 | 215 | $stackPtrCount = 0; |
216 | - if ( isset( $tokens[ $stackPtr ]['nested_parenthesis'] ) ) { |
|
217 | - $stackPtrCount = count( $tokens[ $stackPtr ]['nested_parenthesis'] ); |
|
216 | + if ( isset( $tokens[ $stackPtr ][ 'nested_parenthesis' ] ) ) { |
|
217 | + $stackPtrCount = count( $tokens[ $stackPtr ][ 'nested_parenthesis' ] ); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | $commaCount = 0; |
221 | - if ( isset( $tokens[ $nextToken ]['nested_parenthesis'] ) ) { |
|
222 | - $commaCount = count( $tokens[ $nextToken ]['nested_parenthesis'] ); |
|
223 | - if ( T_ARRAY === $tokens[ $stackPtr ]['code'] ) { |
|
221 | + if ( isset( $tokens[ $nextToken ][ 'nested_parenthesis' ] ) ) { |
|
222 | + $commaCount = count( $tokens[ $nextToken ][ 'nested_parenthesis' ] ); |
|
223 | + if ( T_ARRAY === $tokens[ $stackPtr ][ 'code' ] ) { |
|
224 | 224 | // Remove parenthesis that are used to define the array. |
225 | 225 | $commaCount--; |
226 | 226 | } |
@@ -234,12 +234,12 @@ discard block |
||
234 | 234 | } |
235 | 235 | |
236 | 236 | if ( false === $keyUsed ) { |
237 | - if ( T_WHITESPACE === $tokens[ ( $nextToken - 1 ) ]['code'] ) { |
|
238 | - $content = $tokens[ ( $nextToken - 2 ) ]['content']; |
|
239 | - if ( $tokens[ ( $nextToken - 1 ) ]['content'] === $phpcsFile->eolChar ) { |
|
237 | + if ( T_WHITESPACE === $tokens[ ( $nextToken - 1 ) ][ 'code' ] ) { |
|
238 | + $content = $tokens[ ( $nextToken - 2 ) ][ 'content' ]; |
|
239 | + if ( $tokens[ ( $nextToken - 1 ) ][ 'content' ] === $phpcsFile->eolChar ) { |
|
240 | 240 | $spaceLength = 'newline'; |
241 | 241 | } else { |
242 | - $spaceLength = $tokens[ ( $nextToken - 1 ) ]['length']; |
|
242 | + $spaceLength = $tokens[ ( $nextToken - 1 ) ][ 'length' ]; |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | $error = 'Expected 0 spaces between "%s" and comma; %s found'; |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | true |
262 | 262 | ); |
263 | 263 | |
264 | - $indices[] = array( 'value' => $valueContent ); |
|
264 | + $indices[ ] = array( 'value' => $valueContent ); |
|
265 | 265 | $singleUsed = true; |
266 | 266 | } // end if |
267 | 267 | |
@@ -269,9 +269,9 @@ discard block |
||
269 | 269 | continue; |
270 | 270 | } // end if |
271 | 271 | |
272 | - if ( T_DOUBLE_ARROW === $tokens[ $nextToken ]['code'] ) { |
|
272 | + if ( T_DOUBLE_ARROW === $tokens[ $nextToken ][ 'code' ] ) { |
|
273 | 273 | |
274 | - $currentEntry['arrow'] = $nextToken; |
|
274 | + $currentEntry[ 'arrow' ] = $nextToken; |
|
275 | 275 | $keyUsed = true; |
276 | 276 | |
277 | 277 | // Find the start of index that uses this double arrow. |
@@ -279,14 +279,14 @@ discard block |
||
279 | 279 | $indexStart = $phpcsFile->findStartOfStatement( $indexEnd ); |
280 | 280 | |
281 | 281 | if ( $indexStart === $indexEnd ) { |
282 | - $currentEntry['index'] = $indexEnd; |
|
283 | - $currentEntry['index_content'] = $tokens[ $indexEnd ]['content']; |
|
282 | + $currentEntry[ 'index' ] = $indexEnd; |
|
283 | + $currentEntry[ 'index_content' ] = $tokens[ $indexEnd ][ 'content' ]; |
|
284 | 284 | } else { |
285 | - $currentEntry['index'] = $indexStart; |
|
286 | - $currentEntry['index_content'] = $phpcsFile->getTokensAsString( $indexStart, ( $indexEnd - $indexStart + 1 ) ); |
|
285 | + $currentEntry[ 'index' ] = $indexStart; |
|
286 | + $currentEntry[ 'index_content' ] = $phpcsFile->getTokensAsString( $indexStart, ( $indexEnd - $indexStart + 1 ) ); |
|
287 | 287 | } |
288 | 288 | |
289 | - $indexLength = strlen( $currentEntry['index_content'] ); |
|
289 | + $indexLength = strlen( $currentEntry[ 'index_content' ] ); |
|
290 | 290 | if ( $maxLength < $indexLength ) { |
291 | 291 | $maxLength = $indexLength; |
292 | 292 | } |
@@ -299,8 +299,8 @@ discard block |
||
299 | 299 | true |
300 | 300 | ); |
301 | 301 | |
302 | - $currentEntry['value'] = $nextContent; |
|
303 | - $indices[] = $currentEntry; |
|
302 | + $currentEntry[ 'value' ] = $nextContent; |
|
303 | + $indices[ ] = $currentEntry; |
|
304 | 304 | $lastToken = $nextToken; |
305 | 305 | } // end if |
306 | 306 | } // end for |
@@ -310,11 +310,11 @@ discard block |
||
310 | 310 | |
311 | 311 | if ( empty( $indices ) ) { |
312 | 312 | $singleValue = true; |
313 | - } elseif ( 1 === count( $indices ) && T_COMMA === $tokens[ $lastToken ]['code'] ) { |
|
313 | + } elseif ( 1 === count( $indices ) && T_COMMA === $tokens[ $lastToken ][ 'code' ] ) { |
|
314 | 314 | // There may be another array value without a comma. |
315 | 315 | $exclude = PHP_CodeSniffer_Tokens::$emptyTokens; |
316 | - $exclude[] = T_COMMA; |
|
317 | - $nextContent = $phpcsFile->findNext( $exclude, ( $indices[0]['value'] + 1 ), $arrayEnd, true ); |
|
316 | + $exclude[ ] = T_COMMA; |
|
317 | + $nextContent = $phpcsFile->findNext( $exclude, ( $indices[ 0 ][ 'value' ] + 1 ), $arrayEnd, true ); |
|
318 | 318 | if ( false === $nextContent ) { |
319 | 319 | $singleValue = true; |
320 | 320 | } |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | |
334 | 334 | if ( false === $keyUsed && ! empty( $indices ) ) { |
335 | 335 | $count = count( $indices ); |
336 | - $lastIndex = $indices[ ( $count - 1 ) ]['value']; |
|
336 | + $lastIndex = $indices[ ( $count - 1 ) ][ 'value' ]; |
|
337 | 337 | |
338 | 338 | $trailingContent = $phpcsFile->findPrevious( |
339 | 339 | PHP_CodeSniffer_Tokens::$emptyTokens, |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | true |
343 | 343 | ); |
344 | 344 | |
345 | - if ( T_COMMA !== $tokens[ $trailingContent ]['code'] ) { |
|
345 | + if ( T_COMMA !== $tokens[ $trailingContent ][ 'code' ] ) { |
|
346 | 346 | $phpcsFile->recordMetric( $stackPtr, 'Array end comma', 'no' ); |
347 | 347 | $error = 'Comma required after last value in array declaration'; |
348 | 348 | $fix = $phpcsFile->addFixableError( $error, $trailingContent, 'NoCommaAfterLast' ); |
@@ -355,26 +355,26 @@ discard block |
||
355 | 355 | |
356 | 356 | $lastValueLine = false; |
357 | 357 | foreach ( $indices as $value ) { |
358 | - if ( empty( $value['value'] ) ) { |
|
358 | + if ( empty( $value[ 'value' ] ) ) { |
|
359 | 359 | // Array was malformed and we couldn't figure out |
360 | 360 | // the array value correctly, so we have to ignore it. |
361 | 361 | // Other parts of this sniff will correct the error. |
362 | 362 | continue; |
363 | 363 | } |
364 | 364 | |
365 | - if ( false !== $lastValueLine && $tokens[ $value['value'] ]['line'] === $lastValueLine ) { |
|
365 | + if ( false !== $lastValueLine && $tokens[ $value[ 'value' ] ][ 'line' ] === $lastValueLine ) { |
|
366 | 366 | $error = 'Each value in a multi-line array must be on a new line'; |
367 | - $fix = $phpcsFile->addFixableError( $error, $value['value'], 'ValueNoNewline' ); |
|
367 | + $fix = $phpcsFile->addFixableError( $error, $value[ 'value' ], 'ValueNoNewline' ); |
|
368 | 368 | if ( true === $fix ) { |
369 | - if ( T_WHITESPACE === $tokens[ ( $value['value'] - 1 ) ]['code'] ) { |
|
370 | - $phpcsFile->fixer->replaceToken( ( $value['value'] - 1 ), '' ); |
|
369 | + if ( T_WHITESPACE === $tokens[ ( $value[ 'value' ] - 1 ) ][ 'code' ] ) { |
|
370 | + $phpcsFile->fixer->replaceToken( ( $value[ 'value' ] - 1 ), '' ); |
|
371 | 371 | } |
372 | 372 | |
373 | - $phpcsFile->fixer->addNewlineBefore( $value['value'] ); |
|
373 | + $phpcsFile->fixer->addNewlineBefore( $value[ 'value' ] ); |
|
374 | 374 | } |
375 | 375 | } // end if |
376 | 376 | |
377 | - $lastValueLine = $tokens[ $value['value'] ]['line']; |
|
377 | + $lastValueLine = $tokens[ $value[ 'value' ] ][ 'line' ]; |
|
378 | 378 | } // end foreach |
379 | 379 | } // end if |
380 | 380 | |
@@ -410,16 +410,16 @@ discard block |
||
410 | 410 | $indicesStart = ( $keywordStart + 1 ); |
411 | 411 | $arrowStart = ( $indicesStart + $maxLength + 1 ); |
412 | 412 | $valueStart = ( $arrowStart + 3 ); |
413 | - $indexLine = $tokens[ $stackPtr ]['line']; |
|
413 | + $indexLine = $tokens[ $stackPtr ][ 'line' ]; |
|
414 | 414 | $lastIndexLine = null; |
415 | 415 | foreach ( $indices as $index ) { |
416 | - if ( ! isset( $index['index'] ) ) { |
|
416 | + if ( ! isset( $index[ 'index' ] ) ) { |
|
417 | 417 | // Array value only. |
418 | - if ( $tokens[ $index['value'] ]['line'] === $tokens[ $stackPtr ]['line'] && $numValues > 1 ) { |
|
418 | + if ( $tokens[ $index[ 'value' ] ][ 'line' ] === $tokens[ $stackPtr ][ 'line' ] && $numValues > 1 ) { |
|
419 | 419 | $error = 'The first value in a multi-value array must be on a new line'; |
420 | 420 | $fix = $phpcsFile->addFixableError( $error, $stackPtr, 'FirstValueNoNewline' ); |
421 | 421 | if ( true === $fix ) { |
422 | - $phpcsFile->fixer->addNewlineBefore( $index['value'] ); |
|
422 | + $phpcsFile->fixer->addNewlineBefore( $index[ 'value' ] ); |
|
423 | 423 | } |
424 | 424 | } |
425 | 425 | |
@@ -427,13 +427,13 @@ discard block |
||
427 | 427 | } |
428 | 428 | |
429 | 429 | $lastIndexLine = $indexLine; |
430 | - $indexLine = $tokens[ $index['index'] ]['line']; |
|
430 | + $indexLine = $tokens[ $index[ 'index' ] ][ 'line' ]; |
|
431 | 431 | |
432 | - if ( $indexLine === $tokens[ $stackPtr ]['line'] ) { |
|
432 | + if ( $indexLine === $tokens[ $stackPtr ][ 'line' ] ) { |
|
433 | 433 | $error = 'The first index in a multi-value array must be on a new line'; |
434 | - $fix = $phpcsFile->addFixableError( $error, $index['index'], 'FirstIndexNoNewline' ); |
|
434 | + $fix = $phpcsFile->addFixableError( $error, $index[ 'index' ], 'FirstIndexNoNewline' ); |
|
435 | 435 | if ( true === $fix ) { |
436 | - $phpcsFile->fixer->addNewlineBefore( $index['index'] ); |
|
436 | + $phpcsFile->fixer->addNewlineBefore( $index[ 'index' ] ); |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | continue; |
@@ -441,48 +441,48 @@ discard block |
||
441 | 441 | |
442 | 442 | if ( $indexLine === $lastIndexLine ) { |
443 | 443 | $error = 'Each index in a multi-line array must be on a new line'; |
444 | - $fix = $phpcsFile->addFixableError( $error, $index['index'], 'IndexNoNewline' ); |
|
444 | + $fix = $phpcsFile->addFixableError( $error, $index[ 'index' ], 'IndexNoNewline' ); |
|
445 | 445 | if ( true === $fix ) { |
446 | - if ( T_WHITESPACE === $tokens[ ( $index['index'] - 1 ) ]['code'] ) { |
|
447 | - $phpcsFile->fixer->replaceToken( ( $index['index'] - 1 ), '' ); |
|
446 | + if ( T_WHITESPACE === $tokens[ ( $index[ 'index' ] - 1 ) ][ 'code' ] ) { |
|
447 | + $phpcsFile->fixer->replaceToken( ( $index[ 'index' ] - 1 ), '' ); |
|
448 | 448 | } |
449 | 449 | |
450 | - $phpcsFile->fixer->addNewlineBefore( $index['index'] ); |
|
450 | + $phpcsFile->fixer->addNewlineBefore( $index[ 'index' ] ); |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | continue; |
454 | 454 | } |
455 | 455 | |
456 | 456 | // Check each line ends in a comma. |
457 | - $valueLine = $tokens[ $index['value'] ]['line']; |
|
457 | + $valueLine = $tokens[ $index[ 'value' ] ][ 'line' ]; |
|
458 | 458 | $nextComma = false; |
459 | - for ( $i = $index['value']; $i < $arrayEnd; $i++ ) { |
|
459 | + for ( $i = $index[ 'value' ]; $i < $arrayEnd; $i++ ) { |
|
460 | 460 | // Skip bracketed statements, like function calls. |
461 | - if ( T_OPEN_PARENTHESIS === $tokens[ $i ]['code'] ) { |
|
462 | - $i = $tokens[ $i ]['parenthesis_closer']; |
|
463 | - $valueLine = $tokens[ $i ]['line']; |
|
461 | + if ( T_OPEN_PARENTHESIS === $tokens[ $i ][ 'code' ] ) { |
|
462 | + $i = $tokens[ $i ][ 'parenthesis_closer' ]; |
|
463 | + $valueLine = $tokens[ $i ][ 'line' ]; |
|
464 | 464 | continue; |
465 | 465 | } |
466 | 466 | |
467 | - if ( T_ARRAY === $tokens[ $i ]['code'] ) { |
|
468 | - $i = $tokens[ $tokens[ $i ]['parenthesis_opener'] ]['parenthesis_closer']; |
|
469 | - $valueLine = $tokens[ $i ]['line']; |
|
467 | + if ( T_ARRAY === $tokens[ $i ][ 'code' ] ) { |
|
468 | + $i = $tokens[ $tokens[ $i ][ 'parenthesis_opener' ] ][ 'parenthesis_closer' ]; |
|
469 | + $valueLine = $tokens[ $i ][ 'line' ]; |
|
470 | 470 | continue; |
471 | 471 | } |
472 | 472 | |
473 | - if ( T_OPEN_SHORT_ARRAY === $tokens[ $i ]['code'] ) { |
|
474 | - $i = $tokens[ $i ]['bracket_closer']; |
|
475 | - $valueLine = $tokens[ $i ]['line']; |
|
473 | + if ( T_OPEN_SHORT_ARRAY === $tokens[ $i ][ 'code' ] ) { |
|
474 | + $i = $tokens[ $i ][ 'bracket_closer' ]; |
|
475 | + $valueLine = $tokens[ $i ][ 'line' ]; |
|
476 | 476 | continue; |
477 | 477 | } |
478 | 478 | |
479 | - if ( T_CLOSURE === $tokens[ $i ]['code'] ) { |
|
480 | - $i = $tokens[ $i ]['scope_closer']; |
|
481 | - $valueLine = $tokens[ $i ]['line']; |
|
479 | + if ( T_CLOSURE === $tokens[ $i ][ 'code' ] ) { |
|
480 | + $i = $tokens[ $i ][ 'scope_closer' ]; |
|
481 | + $valueLine = $tokens[ $i ][ 'line' ]; |
|
482 | 482 | continue; |
483 | 483 | } |
484 | 484 | |
485 | - if ( T_COMMA === $tokens[ $i ]['code'] ) { |
|
485 | + if ( T_COMMA === $tokens[ $i ][ 'code' ] ) { |
|
486 | 486 | $nextComma = $i; |
487 | 487 | break; |
488 | 488 | } |
@@ -490,12 +490,12 @@ discard block |
||
490 | 490 | |
491 | 491 | if ( false === $nextComma ) { |
492 | 492 | $error = 'Each line in an array declaration must end in a comma'; |
493 | - $fix = $phpcsFile->addFixableError( $error, $index['value'], 'NoComma' ); |
|
493 | + $fix = $phpcsFile->addFixableError( $error, $index[ 'value' ], 'NoComma' ); |
|
494 | 494 | |
495 | 495 | if ( true === $fix ) { |
496 | 496 | // Find the end of the line and put a comma there. |
497 | - for ( $i = ( $index['value'] + 1 ); $i < $phpcsFile->numTokens; $i++ ) { |
|
498 | - if ( $tokens[ $i ]['line'] > $valueLine ) { |
|
497 | + for ( $i = ( $index[ 'value' ] + 1 ); $i < $phpcsFile->numTokens; $i++ ) { |
|
498 | + if ( $tokens[ $i ][ 'line' ] > $valueLine ) { |
|
499 | 499 | break; |
500 | 500 | } |
501 | 501 | } |
@@ -505,9 +505,9 @@ discard block |
||
505 | 505 | } |
506 | 506 | |
507 | 507 | // Check that there is no space before the comma. |
508 | - if ( false !== $nextComma && T_WHITESPACE === $tokens[ ( $nextComma - 1 ) ]['code'] ) { |
|
509 | - $content = $tokens[ ( $nextComma - 2 ) ]['content']; |
|
510 | - $spaceLength = $tokens[ ( $nextComma - 1 ) ]['length']; |
|
508 | + if ( false !== $nextComma && T_WHITESPACE === $tokens[ ( $nextComma - 1 ) ][ 'code' ] ) { |
|
509 | + $content = $tokens[ ( $nextComma - 2 ) ][ 'content' ]; |
|
510 | + $spaceLength = $tokens[ ( $nextComma - 1 ) ][ 'length' ]; |
|
511 | 511 | $error = 'Expected 0 spaces between "%s" and comma; %s found'; |
512 | 512 | $data = array( |
513 | 513 | $content, |
@@ -47,7 +47,7 @@ |
||
47 | 47 | public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { |
48 | 48 | $tokens = $phpcsFile->getTokens(); |
49 | 49 | |
50 | - if ( '$_SESSION' === $tokens[ $stackPtr ]['content'] ) { |
|
50 | + if ( '$_SESSION' === $tokens[ $stackPtr ][ 'content' ] ) { |
|
51 | 51 | $phpcsFile->addError( 'Usage of $_SESSION variable is prohibited.', $stackPtr, 'SessionVarsProhibited' ); |
52 | 52 | } |
53 | 53 |
@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | $tokens = $phpcsFile->getTokens(); |
45 | 45 | $token = $tokens[ $stackPtr ]; |
46 | 46 | |
47 | - if ( 'cron_schedules' !== trim( $token['content'], '"\'' ) ) { |
|
47 | + if ( 'cron_schedules' !== trim( $token[ 'content' ], '"\'' ) ) { |
|
48 | 48 | return; |
49 | 49 | } |
50 | 50 | |
51 | 51 | // If within add_filter. |
52 | - $functionPtr = $phpcsFile->findPrevious( T_STRING, key( $token['nested_parenthesis'] ) ); |
|
53 | - if ( 'add_filter' !== $tokens[ $functionPtr ]['content'] ) { |
|
52 | + $functionPtr = $phpcsFile->findPrevious( T_STRING, key( $token[ 'nested_parenthesis' ] ) ); |
|
53 | + if ( 'add_filter' !== $tokens[ $functionPtr ][ 'content' ] ) { |
|
54 | 54 | return; |
55 | 55 | } |
56 | 56 | |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | $callbackPtr = $phpcsFile->findNext( array( T_COMMA, T_WHITESPACE ), ( $stackPtr + 1 ), null, true, null, true ); |
59 | 59 | |
60 | 60 | // If callback is array, get second element. |
61 | - if ( T_ARRAY === $tokens[ $callbackPtr ]['code'] ) { |
|
61 | + if ( T_ARRAY === $tokens[ $callbackPtr ][ 'code' ] ) { |
|
62 | 62 | $comma = $phpcsFile->findNext( T_COMMA, ( $callbackPtr + 1 ) ); |
63 | 63 | if ( false === $comma ) { |
64 | 64 | $this->confused( $phpcsFile, $stackPtr ); |
@@ -75,15 +75,15 @@ discard block |
||
75 | 75 | $functionPtr = null; |
76 | 76 | |
77 | 77 | // Search for the function in tokens. |
78 | - if ( in_array( $tokens[ $callbackPtr ]['code'], array( T_CONSTANT_ENCAPSED_STRING, T_DOUBLE_QUOTED_STRING ), true ) ) { |
|
79 | - $functionName = trim( $tokens[ $callbackPtr ]['content'], '"\'' ); |
|
78 | + if ( in_array( $tokens[ $callbackPtr ][ 'code' ], array( T_CONSTANT_ENCAPSED_STRING, T_DOUBLE_QUOTED_STRING ), true ) ) { |
|
79 | + $functionName = trim( $tokens[ $callbackPtr ][ 'content' ], '"\'' ); |
|
80 | 80 | |
81 | 81 | foreach ( $tokens as $ptr => $_token ) { |
82 | - if ( T_STRING === $_token['code'] && $_token['content'] === $functionName ) { |
|
82 | + if ( T_STRING === $_token[ 'code' ] && $_token[ 'content' ] === $functionName ) { |
|
83 | 83 | $functionPtr = $ptr; |
84 | 84 | } |
85 | 85 | } |
86 | - } elseif ( T_CLOSURE === $tokens[ $callbackPtr ]['code'] ) { // Closure. |
|
86 | + } elseif ( T_CLOSURE === $tokens[ $callbackPtr ][ 'code' ] ) { // Closure. |
|
87 | 87 | $functionPtr = $callbackPtr; |
88 | 88 | } |
89 | 89 | |
@@ -93,11 +93,11 @@ discard block |
||
93 | 93 | } |
94 | 94 | |
95 | 95 | $opening = $phpcsFile->findNext( T_OPEN_CURLY_BRACKET, $functionPtr ); |
96 | - $closing = $tokens[ $opening ]['bracket_closer']; |
|
96 | + $closing = $tokens[ $opening ][ 'bracket_closer' ]; |
|
97 | 97 | for ( $i = $opening; $i <= $closing; $i++ ) { |
98 | 98 | |
99 | - if ( in_array( $tokens[ $i ]['code'], array( T_CONSTANT_ENCAPSED_STRING, T_DOUBLE_QUOTED_STRING ), true ) ) { |
|
100 | - if ( 'interval' === trim( $tokens[ $i ]['content'], '\'"' ) ) { |
|
99 | + if ( in_array( $tokens[ $i ][ 'code' ], array( T_CONSTANT_ENCAPSED_STRING, T_DOUBLE_QUOTED_STRING ), true ) ) { |
|
100 | + if ( 'interval' === trim( $tokens[ $i ][ 'content' ], '\'"' ) ) { |
|
101 | 101 | $operator = $phpcsFile->findNext( T_DOUBLE_ARROW, $i, null, null, null, true ); |
102 | 102 | if ( empty( $operator ) ) { |
103 | 103 | $this->confused( $phpcsFile, $stackPtr ); |
@@ -83,7 +83,8 @@ |
||
83 | 83 | $functionPtr = $ptr; |
84 | 84 | } |
85 | 85 | } |
86 | - } elseif ( T_CLOSURE === $tokens[ $callbackPtr ]['code'] ) { // Closure. |
|
86 | + } elseif ( T_CLOSURE === $tokens[ $callbackPtr ]['code'] ) { |
|
87 | +// Closure. |
|
87 | 88 | $functionPtr = $callbackPtr; |
88 | 89 | } |
89 | 90 |
@@ -44,7 +44,7 @@ |
||
44 | 44 | public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { |
45 | 45 | $tokens = $phpcsFile->getTokens(); |
46 | 46 | |
47 | - if ( in_array( trim( $tokens[ $stackPtr ]['content'], '"\'' ), array( 'show_admin_bar' ), true ) ) { |
|
47 | + if ( in_array( trim( $tokens[ $stackPtr ][ 'content' ], '"\'' ), array( 'show_admin_bar' ), true ) ) { |
|
48 | 48 | $phpcsFile->addError( 'Removal of admin bar is prohibited.', $stackPtr, 'RemovalDetected' ); |
49 | 49 | } |
50 | 50 | } // end process() |