@@ -2154,32 +2154,45 @@ private static function _recurseScopeMap(
21542154 && $ opener === null
21552155 ) {
21562156 if ($ tokenType === T_OPEN_CURLY_BRACKET ) {
2157- // Make sure this is actually an opener and not a
2158- // string offset (e.g., $var{0}).
2159- for ($ x = ($ i - 1 ); $ x > 0 ; $ x --) {
2160- if (isset (PHP_CodeSniffer_Tokens::$ emptyTokens [$ tokens [$ x ]['code ' ]]) === true ) {
2161- continue ;
2162- } else {
2163- // If the first non-whitespace/comment token is a
2164- // variable or object operator then this is an opener
2165- // for a string offset and not a scope.
2166- if ($ tokens [$ x ]['code ' ] === T_VARIABLE
2167- || $ tokens [$ x ]['code ' ] === T_OBJECT_OPERATOR
2168- ) {
2169- if (PHP_CODESNIFFER_VERBOSITY > 1 ) {
2170- echo str_repeat ("\t" , $ depth );
2171- echo '* ignoring curly brace * ' .PHP_EOL ;
2172- }
2157+ if (isset ($ tokens [$ stackPtr ]['parenthesis_closer ' ]) === true
2158+ && $ i < $ tokens [$ stackPtr ]['parenthesis_closer ' ]
2159+ ) {
2160+ // We found a curly brace inside the condition of the
2161+ // current scope opener, so it must be a string offset.
2162+ if (PHP_CODESNIFFER_VERBOSITY > 1 ) {
2163+ echo str_repeat ("\t" , $ depth );
2164+ echo '* ignoring curly brace * ' .PHP_EOL ;
2165+ }
21732166
2174- $ ignore ++;
2175- }//end if
2167+ $ ignore ++;
2168+ } else {
2169+ // Make sure this is actually an opener and not a
2170+ // string offset (e.g., $var{0}).
2171+ for ($ x = ($ i - 1 ); $ x > 0 ; $ x --) {
2172+ if (isset (PHP_CodeSniffer_Tokens::$ emptyTokens [$ tokens [$ x ]['code ' ]]) === true ) {
2173+ continue ;
2174+ } else {
2175+ // If the first non-whitespace/comment token is a
2176+ // variable or object operator then this is an opener
2177+ // for a string offset and not a scope.
2178+ if ($ tokens [$ x ]['code ' ] === T_VARIABLE
2179+ || $ tokens [$ x ]['code ' ] === T_OBJECT_OPERATOR
2180+ ) {
2181+ if (PHP_CODESNIFFER_VERBOSITY > 1 ) {
2182+ echo str_repeat ("\t" , $ depth );
2183+ echo '* ignoring curly brace * ' .PHP_EOL ;
2184+ }
21762185
2177- break ;
2178- }//end if
2179- }//end for
2186+ $ ignore ++;
2187+ }//end if
2188+
2189+ break ;
2190+ }//end if
2191+ }//end for
2192+ }//end if
21802193 }//end if
21812194
2182- if ($ ignore === 0 ) {
2195+ if ($ ignore === 0 || $ tokenType !== T_OPEN_CURLY_BRACKET ) {
21832196 // We found the opening scope token for $currType.
21842197 if (PHP_CODESNIFFER_VERBOSITY > 1 ) {
21852198 $ type = $ tokens [$ stackPtr ]['type ' ];
@@ -2196,22 +2209,13 @@ private static function _recurseScopeMap(
21962209 && isset ($ tokens [$ i ]['parenthesis_closer ' ]) === true
21972210 ) {
21982211 // If we get into here, then we opened a parenthesis for
2199- // a scope (eg. an if or else if). We can just skip to
2200- // the closing parenthesis.
2201- $ i = $ tokens [$ i ]['parenthesis_closer ' ];
2202-
2203- // Update the start of the line so that when we check to see
2212+ // a scope (eg. an if or else if) so we need to update the
2213+ // start of the line so that when we check to see
22042214 // if the closing parenthesis is more than 3 lines away from
22052215 // the statement, we check from the closing parenthesis.
2206- $ startLine
2207- = $ tokens [$ tokens [$ i ]['parenthesis_closer ' ]]['line ' ];
2208-
2209- if (PHP_CODESNIFFER_VERBOSITY > 1 ) {
2210- echo str_repeat ("\t" , $ depth );
2211- echo '* skipping parenthesis * ' .PHP_EOL ;
2212- }
2216+ $ startLine = $ tokens [$ tokens [$ i ]['parenthesis_closer ' ]]['line ' ];
22132217 }
2214- }//end if
2218+ }
22152219 } else if ($ tokenType === T_OPEN_CURLY_BRACKET && $ opener !== null ) {
22162220 // We opened something that we don't have a scope opener for.
22172221 // Examples of this are curly brackets for string offsets etc.
@@ -2223,6 +2227,14 @@ private static function _recurseScopeMap(
22232227 }
22242228
22252229 $ ignore ++;
2230+ } else if ($ tokenType === T_CLOSE_CURLY_BRACKET && $ ignore > 0 ) {
2231+ // We found the end token for the opener we were ignoring.
2232+ if (PHP_CODESNIFFER_VERBOSITY > 1 ) {
2233+ echo str_repeat ("\t" , $ depth );
2234+ echo '* finished ignoring curly brace * ' .PHP_EOL ;
2235+ }
2236+
2237+ $ ignore --;
22262238 } else if ($ opener === null
22272239 && isset ($ tokenizer ->scopeOpeners [$ currType ]) === true
22282240 ) {
0 commit comments