Skip to content

Commit c9c072f

Browse files
authored
Prevent ImportsFromTestNamespaceSniff from hanging when group use declaration has trailing coma.
If a grouped use statement has a trailing coma like this: ``` use Magento\Something{ Foo, Bar, }; ``` `findNext` on line 59 was returning false and next call was starting to search again from line 1 (`$next + 1`) and this function was looping indefinitely through input tokens.
1 parent 2e163ba commit c9c072f

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ public function process(File $phpcsFile, $stackPtr)
5757
$closingCurly = $phpcsFile->findNext(T_CLOSE_USE_GROUP, ($next + 1));
5858
do {
5959
$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), $closingCurly, true);
60-
$groupedAsContent = $baseUse. $tokens[$next]['content'];
61-
$next = $phpcsFile->findNext(T_COMMA, ($next + 1), $closingCurly);
62-
if (strpos($groupedAsContent, $this->prohibitNamespace) !== false) {
63-
$phpcsFile->addWarning($this->warningMessage, $stackPtr, $this->warningCode);
64-
return;
60+
if ($next !== false) {
61+
$groupedAsContent = $baseUse. $tokens[$next]['content'];
62+
$next = $phpcsFile->findNext(T_COMMA, ($next + 1), $closingCurly);
63+
if (strpos($groupedAsContent, $this->prohibitNamespace) !== false) {
64+
$phpcsFile->addWarning($this->warningMessage, $stackPtr, $this->warningCode);
65+
return;
66+
}
6567
}
6668
} while ($next !== false);
6769
}

0 commit comments

Comments
 (0)