Skip to content

Commit

Permalink
Ignore group use statements - we don't support them
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Jun 22, 2022
1 parent 45bbc19 commit c5cf9b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions SlevomatCodingStandard/Helpers/UseStatementHelper.php
Expand Up @@ -14,6 +14,7 @@
use const T_NAMESPACE;
use const T_OPEN_PARENTHESIS;
use const T_OPEN_TAG;
use const T_OPEN_USE_GROUP;
use const T_SEMICOLON;
use const T_STRING;
use const T_USE;
Expand Down Expand Up @@ -193,10 +194,17 @@ private static function getUseStatementPointers(File $phpcsFile, int $openTagPoi
$pointer = $token['scope_closer'] + 1;
continue;
}

if (self::isGroupUse($phpcsFile, $pointer)) {
$pointer++;
continue;
}

if (self::isAnonymousFunctionUse($phpcsFile, $pointer)) {
$pointer++;
continue;
}

$pointers[] = $pointer;
$pointer++;
}
Expand All @@ -207,4 +215,12 @@ private static function getUseStatementPointers(File $phpcsFile, int $openTagPoi
return SniffLocalCache::getAndSetIfNotCached($phpcsFile, 'useStatementPointers', $lazy);
}

private static function isGroupUse(File $phpcsFile, int $usePointer): bool
{
$tokens = $phpcsFile->getTokens();
$semicolonOrGroupUsePointer = TokenHelper::findNext($phpcsFile, [T_SEMICOLON, T_OPEN_USE_GROUP], $usePointer + 1);

return $tokens[$semicolonOrGroupUsePointer]['code'] === T_OPEN_USE_GROUP;
}

}
1 change: 1 addition & 0 deletions tests/Helpers/data/useStatements.php
Expand Up @@ -7,6 +7,7 @@
use const Rasmus\FOO;
use function Lerdorf\isBar;
use function Rasmus\foo;
use Doctrine\Common\Collections\Expr\{ Comparison, Value, CompositeExpression };

class FooBar
{
Expand Down

0 comments on commit c5cf9b5

Please sign in to comment.