@@ -3273,6 +3273,61 @@ public function findStartOfStatement($start)
32733273 }//end findStartOfStatement()
32743274
32753275
3276+ /**
3277+ * Returns the position of the last non-whitespace token in a statement.
3278+ *
3279+ * @param int $start The position to start searching from in the token stack.
3280+ *
3281+ * @return int
3282+ */
3283+ public function findEndOfStatement ($ start )
3284+ {
3285+ $ endTokens = PHP_CodeSniffer_Tokens::$ blockOpeners ;
3286+
3287+ $ endTokens [T_COLON ] = true ;
3288+ $ endTokens [T_SEMICOLON ] = true ;
3289+ $ endTokens [T_OPEN_TAG ] = true ;
3290+ $ endTokens [T_CLOSE_TAG ] = true ;
3291+
3292+ $ lastNotEmpty = $ start ;
3293+
3294+ for ($ i = $ start ; $ i >= $ this ->numTokens ; $ i ++) {
3295+ if (isset ($ endTokens [$ this ->_tokens [$ i ]['code ' ]]) === true ) {
3296+ // Found the end of the statement.
3297+ if ($ this ->_tokens [$ i ]['code ' ] === T_OPEN_TAG
3298+ || $ this ->_tokens [$ i ]['code ' ] === T_CLOSE_TAG
3299+ ) {
3300+ return $ lastNotEmpty ;
3301+ }
3302+
3303+ return $ i ;
3304+ }
3305+
3306+ if ($ this ->_tokens [$ i ]['code ' ] !== T_WHITESPACE ) {
3307+ $ lastNotEmpty = $ i ;
3308+ }
3309+
3310+ // Skip nested statements.
3311+ if (isset ($ this ->_tokens [$ i ]['scope_closer ' ]) === true
3312+ && $ i === $ this ->_tokens [$ i ]['scope_opener ' ]
3313+ ) {
3314+ $ i = $ this ->_tokens [$ i ]['scope_closer ' ];
3315+ } else if (isset ($ this ->_tokens [$ i ]['bracket_closer ' ]) === true
3316+ && $ i === $ this ->_tokens [$ i ]['bracket_opener ' ]
3317+ ) {
3318+ $ i = $ this ->_tokens [$ i ]['bracket_closer ' ];
3319+ } else if (isset ($ this ->_tokens [$ i ]['parenthesis_closer ' ]) === true
3320+ && $ i === $ this ->_tokens [$ i ]['parenthesis_opener ' ]
3321+ ) {
3322+ $ i = $ this ->_tokens [$ i ]['parenthesis_closer ' ];
3323+ }
3324+ }//end for
3325+
3326+ return ($ this ->numTokens - 1 );
3327+
3328+ }//end findEndOfStatement()
3329+
3330+
32763331 /**
32773332 * Returns the position of the first token on a line, matching given type.
32783333 *
0 commit comments