Skip to content

Commit d0d9ea9

Browse files
authored
Allow whitespace and comments in group import namespace (#48)
* Add test for whitespace at end of import namespace * Allow whitespace after group import namespace * Add test for comment at end of group import namespace
1 parent a732d20 commit d0d9ea9

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

ImportDetection/SniffHelpers.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ private function getImportedSymbolsFromGroupStatement(File $phpcsFile, int $stac
9393
}
9494

9595
// Get the namespace for the import first, so we can attach it to each Symbol
96-
$importPrefixSymbol = $this->getFullSymbol($phpcsFile, $startBracketPtr - 1);
96+
$endOfImportNamespace = $phpcsFile->findPrevious([T_NS_SEPARATOR], $startBracketPtr - 1);
97+
if (! $endOfImportNamespace) {
98+
throw new \Exception('Unable to parse namespace for group import statement starting at token ' . $stackPtr . ': ' . $tokens[$stackPtr]['content']);
99+
}
100+
$importPrefixSymbol = $this->getFullSymbol($phpcsFile, $endOfImportNamespace);
97101

98102
$collectedSymbols = [];
99103
$lastStringPtr = $startBracketPtr;

tests/Sniffs/Imports/Fixtures/ClassFixtures.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,22 @@
99
E\F, // used line 15
1010
I\J as H, // not used
1111
};
12+
use Some\NS\ {
13+
ClassName,
14+
function SubLevel\functionName,
15+
const Constants\CONSTANT_NAME as SOME_CONSTANT,
16+
function SubLevel\AnotherName,
17+
};
18+
use Some\NS\/* test comment with a backslash \ */{
19+
AnotherLevel,
20+
};
1221

1322
A::class;
1423
Z::class;
1524
F::class;
25+
26+
echo ClassName::class;
27+
echo functionName();
28+
echo SOME_CONSTANT;
29+
echo AnotherName();
30+
echo AnotherLevel::class;

0 commit comments

Comments
 (0)