*/ public function register() { return Collections::shortArrayListOpenTokensBC(); } /** * Processes this test, when one of its tokens is encountered. * * @since 9.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 int|void Integer stack pointer to skip forward or void to continue * normal file processing. */ public function process(File $phpcsFile, $stackPtr) { if (ScannedCode::shouldRunOnOrBelow('7.0') === false) { return; } if (Lists::isShortList($phpcsFile, $stackPtr) === false) { return; } $tokens = $phpcsFile->getTokens(); $closer = $tokens[$stackPtr]['bracket_closer']; $hasVariable = $phpcsFile->findNext(\T_VARIABLE, ($stackPtr + 1), $closer); if ($hasVariable === false) { // List syntax is only valid if there are variables in it. return; } $phpcsFile->addError( 'The shorthand list syntax "[]" to destructure arrays is not available in PHP 7.0 or earlier.', $stackPtr, 'Found' ); return ($closer + 1); } }