*/ public function register() { return [\T_CLASS, \T_ANON_CLASS]; } /** * Processes this test, when one of its tokens is encountered. * * @since 10.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) { $tokens = $phpcsFile->getTokens(); if ($tokens[$stackPtr]['code'] === \T_CLASS) { if (ScannedCode::shouldRunOnOrBelow('8.1') === \false) { return; } $properties = ObjectDeclarations::getClassProperties($phpcsFile, $stackPtr); if ($properties['is_readonly'] === \false) { return; } $phpcsFile->addError('Readonly classes are not supported in PHP 8.1 or earlier.', $properties['readonly_token'], 'Found'); } if ($tokens[$stackPtr]['code'] === \T_ANON_CLASS) { if (ScannedCode::shouldRunOnOrBelow('8.2') === \false) { return; } $prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, $stackPtr - 1, null, \true); if ($tokens[$prevNonEmpty]['code'] === \T_READONLY) { $phpcsFile->addError('Readonly anonymous classes are not supported in PHP 8.2 or earlier.', $prevNonEmpty, 'AnonClass'); } } } }