*/ public function register() { return [ \T_OPEN_USE_GROUP, \T_CLOSE_USE_GROUP, ]; } /** * Processes this test, when one of its tokens is encountered. * * @since 7.0.0 * * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. * @param int $stackPtr The position of the current token in * the stack passed in $tokens. * * @return void */ public function process(File $phpcsFile, $stackPtr) { if (ScannedCode::shouldRunOnOrBelow('7.1') === false) { return; } $tokens = $phpcsFile->getTokens(); if ($tokens[$stackPtr]['code'] === \T_OPEN_USE_GROUP && ScannedCode::shouldRunOnOrBelow('5.6') === true ) { $phpcsFile->addError( 'Group use declarations are not allowed in PHP 5.6 or earlier', $stackPtr, 'Found' ); } if ($tokens[$stackPtr]['code'] === \T_CLOSE_USE_GROUP) { $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); if ($tokens[$prevToken]['code'] === \T_COMMA) { $phpcsFile->addError( 'Trailing commas are not allowed in group use statements in PHP 7.1 or earlier', $prevToken, 'TrailingCommaFound' ); } } } }