*/ public function register() { return [\T_CONST]; } /** * 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) { if (ScannedCode::shouldRunOnOrBelow('8.1') === false) { return; } $ooPtr = Scopes::validDirectScope($phpcsFile, $stackPtr, \T_TRAIT); if ($ooPtr === false) { // Not a constant in trait. return; } $phpcsFile->addError( 'Declaring constants in traits is not supported in PHP 8.1 or earlier.', $stackPtr, 'Found' ); } }