Skip to content

Commit 0260750

Browse files
committed
Fixed finding the end of a use block
1 parent aafc304 commit 0260750

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/Files/File.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2343,6 +2343,11 @@ public function findEndOfStatement($start, $ignore=null)
23432343
&& $i === $this->tokens[$i]['parenthesis_opener']
23442344
) {
23452345
$i = $this->tokens[$i]['parenthesis_closer'];
2346+
} else if ($this->tokens[$i]['code'] === T_OPEN_USE_GROUP) {
2347+
$end = $this->findNext(T_CLOSE_USE_GROUP, ($i + 1));
2348+
if ($end !== false) {
2349+
$i = $end;
2350+
}
23462351
}
23472352

23482353
if (isset(Util\Tokens::$emptyTokens[$this->tokens[$i]['code']]) === false) {

tests/Core/File/FindEndOfStatementTest.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ switch ($a) {
2626
$a = [new Datetime];
2727
$a = array(new Datetime);
2828
$a = new Datetime;
29+
30+
/* testUseGroup */
31+
use Vendor\Package\{ClassA as A, ClassB, ClassC as C};

tests/Core/File/FindEndOfStatementTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,20 @@ public function testStatementAsArrayValue()
156156
}//end testStatementAsArrayValue()
157157

158158

159+
/**
160+
* Test a use group.
161+
*
162+
* @return void
163+
*/
164+
public function testUseGroup()
165+
{
166+
$start = (self::$phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testUseGroup */') + 2);
167+
$found = self::$phpcsFile->findEndOfStatement($start);
168+
169+
$tokens = self::$phpcsFile->getTokens();
170+
$this->assertSame($tokens[($start + 23)], $tokens[$found]);
171+
172+
}//end testUseGroup()
173+
174+
159175
}//end class

0 commit comments

Comments
 (0)