Skip to content

Commit c5cf9b5

Browse files
committed
Ignore group use statements - we don't support them
1 parent 45bbc19 commit c5cf9b5

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

SlevomatCodingStandard/Helpers/UseStatementHelper.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use const T_NAMESPACE;
1515
use const T_OPEN_PARENTHESIS;
1616
use const T_OPEN_TAG;
17+
use const T_OPEN_USE_GROUP;
1718
use const T_SEMICOLON;
1819
use const T_STRING;
1920
use const T_USE;
@@ -193,10 +194,17 @@ private static function getUseStatementPointers(File $phpcsFile, int $openTagPoi
193194
$pointer = $token['scope_closer'] + 1;
194195
continue;
195196
}
197+
198+
if (self::isGroupUse($phpcsFile, $pointer)) {
199+
$pointer++;
200+
continue;
201+
}
202+
196203
if (self::isAnonymousFunctionUse($phpcsFile, $pointer)) {
197204
$pointer++;
198205
continue;
199206
}
207+
200208
$pointers[] = $pointer;
201209
$pointer++;
202210
}
@@ -207,4 +215,12 @@ private static function getUseStatementPointers(File $phpcsFile, int $openTagPoi
207215
return SniffLocalCache::getAndSetIfNotCached($phpcsFile, 'useStatementPointers', $lazy);
208216
}
209217

218+
private static function isGroupUse(File $phpcsFile, int $usePointer): bool
219+
{
220+
$tokens = $phpcsFile->getTokens();
221+
$semicolonOrGroupUsePointer = TokenHelper::findNext($phpcsFile, [T_SEMICOLON, T_OPEN_USE_GROUP], $usePointer + 1);
222+
223+
return $tokens[$semicolonOrGroupUsePointer]['code'] === T_OPEN_USE_GROUP;
224+
}
225+
210226
}

tests/Helpers/data/useStatements.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use const Rasmus\FOO;
88
use function Lerdorf\isBar;
99
use function Rasmus\foo;
10+
use Doctrine\Common\Collections\Expr\{ Comparison, Value, CompositeExpression };
1011

1112
class FooBar
1213
{

0 commit comments

Comments
 (0)