Skip to content

Commit

Permalink
Fixed finding the end of a use block
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Aug 29, 2019
1 parent aafc304 commit 0260750
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -2343,6 +2343,11 @@ public function findEndOfStatement($start, $ignore=null)
&& $i === $this->tokens[$i]['parenthesis_opener']
) {
$i = $this->tokens[$i]['parenthesis_closer'];
} else if ($this->tokens[$i]['code'] === T_OPEN_USE_GROUP) {
$end = $this->findNext(T_CLOSE_USE_GROUP, ($i + 1));
if ($end !== false) {
$i = $end;
}
}

if (isset(Util\Tokens::$emptyTokens[$this->tokens[$i]['code']]) === false) {
Expand Down
3 changes: 3 additions & 0 deletions tests/Core/File/FindEndOfStatementTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ switch ($a) {
$a = [new Datetime];
$a = array(new Datetime);
$a = new Datetime;

/* testUseGroup */
use Vendor\Package\{ClassA as A, ClassB, ClassC as C};
16 changes: 16 additions & 0 deletions tests/Core/File/FindEndOfStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,20 @@ public function testStatementAsArrayValue()
}//end testStatementAsArrayValue()


/**
* Test a use group.
*
* @return void
*/
public function testUseGroup()
{
$start = (self::$phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testUseGroup */') + 2);
$found = self::$phpcsFile->findEndOfStatement($start);

$tokens = self::$phpcsFile->getTokens();
$this->assertSame($tokens[($start + 23)], $tokens[$found]);

}//end testUseGroup()


}//end class

0 comments on commit 0260750

Please sign in to comment.