@@ -57,9 +57,7 @@ public function process(File $phpcsFile, $stackPtr)
5757 T_CONSTANT_ENCAPSED_STRING ,
5858 ];
5959
60- if ($ previousIndex === false
61- || in_array ($ tokens [$ previousIndex ]['code ' ], $ relevantTokens , true ) === false
62- ) {
60+ if (in_array ($ tokens [$ previousIndex ]['code ' ], $ relevantTokens , true ) === false ) {
6361 return ;
6462 }
6563
@@ -71,9 +69,6 @@ public function process(File $phpcsFile, $stackPtr)
7169 }
7270
7371 $ prevIndex = $ phpcsFile ->findPrevious (Tokens::$ emptyTokens , ($ previousIndex - 1 ), null , true );
74- if ($ prevIndex === false ) {
75- return ;
76- }
7772
7873 if (in_array ($ tokens [$ prevIndex ]['code ' ], Tokens::$ arithmeticTokens , true ) === true ) {
7974 return ;
@@ -85,16 +80,15 @@ public function process(File $phpcsFile, $stackPtr)
8580
8681 // Is it a parenthesis.
8782 if ($ tokens [$ previousIndex ]['code ' ] === T_CLOSE_PARENTHESIS ) {
88- // Check what exists inside the parenthesis.
89- $ closeParenthesisIndex = $ phpcsFile ->findPrevious (
83+ $ beforeOpeningParenthesisIndex = $ phpcsFile ->findPrevious (
9084 Tokens::$ emptyTokens ,
9185 ($ tokens [$ previousIndex ]['parenthesis_opener ' ] - 1 ),
9286 null ,
9387 true
9488 );
9589
96- if ($ closeParenthesisIndex === false || $ tokens [$ closeParenthesisIndex ]['code ' ] !== T_ARRAY ) {
97- if ($ tokens [$ closeParenthesisIndex ]['code ' ] === T_STRING ) {
90+ if ($ beforeOpeningParenthesisIndex === false || $ tokens [$ beforeOpeningParenthesisIndex ]['code ' ] !== T_ARRAY ) {
91+ if ($ tokens [$ beforeOpeningParenthesisIndex ]['code ' ] === T_STRING ) {
9892 return ;
9993 }
10094
@@ -110,14 +104,14 @@ public function process(File $phpcsFile, $stackPtr)
110104 return ;
111105 }
112106
113- // If there is nothing inside the parenthesis, it it not a Yoda.
107+ // If there is nothing inside the parenthesis, it is not a Yoda condition .
114108 $ opener = $ tokens [$ previousIndex ]['parenthesis_opener ' ];
115109 $ prev = $ phpcsFile ->findPrevious (Tokens::$ emptyTokens , ($ previousIndex - 1 ), ($ opener + 1 ), true );
116110 if ($ prev === false ) {
117111 return ;
118112 }
119- } else if ($ tokens [$ closeParenthesisIndex ]['code ' ] === T_ARRAY
120- && $ this ->isArrayStatic ($ phpcsFile , $ closeParenthesisIndex ) === false
113+ } else if ($ tokens [$ beforeOpeningParenthesisIndex ]['code ' ] === T_ARRAY
114+ && $ this ->isArrayStatic ($ phpcsFile , $ beforeOpeningParenthesisIndex ) === false
121115 ) {
122116 return ;
123117 }//end if
@@ -144,14 +138,14 @@ public function isArrayStatic(File $phpcsFile, $arrayToken)
144138 {
145139 $ tokens = $ phpcsFile ->getTokens ();
146140
147- $ arrayEnd = null ;
148141 if ($ tokens [$ arrayToken ]['code ' ] === T_OPEN_SHORT_ARRAY ) {
149142 $ start = $ arrayToken ;
150143 $ end = $ tokens [$ arrayToken ]['bracket_closer ' ];
151144 } else if ($ tokens [$ arrayToken ]['code ' ] === T_ARRAY ) {
152145 $ start = $ tokens [$ arrayToken ]['parenthesis_opener ' ];
153146 $ end = $ tokens [$ arrayToken ]['parenthesis_closer ' ];
154147 } else {
148+ // Shouldn't be possible but may happen if external sniffs are using this method.
155149 return true ;
156150 }
157151
0 commit comments