*/ private $checkForScopes = [ \T_NAMESPACE => \T_NAMESPACE, ]; /** * Returns an array of tokens this test wants to listen for. * * @since 8.1.0 * * @return array */ public function register() { $this->checkForScopes += Tokens::$ooScopeTokens; return [\T_FUNCTION]; } /** * Processes this test, when one of its tokens is encountered. * * @since 8.1.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::shouldRunOnOrAbove('7.2') === false) { return; } $funcName = FunctionDeclarations::getName($phpcsFile, $stackPtr); if (\strtolower($funcName) !== '__autoload') { return; } if (Scopes::validDirectScope($phpcsFile, $stackPtr, $this->checkForScopes) !== false) { return; } if (Namespaces::determineNamespace($phpcsFile, $stackPtr) !== '') { return; } $error = 'Specifying an autoloader using an __autoload() function is deprecated since PHP 7.2'; $code = 'Deprecated'; $isError = false; if (ScannedCode::shouldRunOnOrAbove('8.0') === true) { $error .= ' and no longer supported since PHP 8.0'; $code = 'Removed'; $isError = true; } MessageHelper::addMessage($phpcsFile, $error, $stackPtr, $isError, $code); } }