\T_CLASS, ); /** * Returns an array of tokens this test wants to listen for. * * @since 7.0.0 * * @return array */ public function register() { if (\defined('T_ANON_CLASS')) { $this->indicators[\T_ANON_CLASS] = \T_ANON_CLASS; } return array(\T_NEW); } /** * Processes this test, when one of its tokens is encountered. * * @since 7.0.0 * * @param \PHP_CodeSniffer_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 ($this->supportsBelow('5.6') === false) { return; } $tokens = $phpcsFile->getTokens(); $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true); if ($nextNonEmpty === false || isset($this->indicators[$tokens[$nextNonEmpty]['code']]) === false) { return; } // Still here ? In that case, it is an anonymous class. $phpcsFile->addError( 'Anonymous classes are not supported in PHP 5.6 or earlier', $stackPtr, 'Found' ); } }