*/ public function register() { return [\T_FUNCTION]; } /** * Processes this test, when one of its tokens is encountered. * * @since 9.2.0 * @since 10.0.0 New error message for abstract private methods in traits. * * @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('5.1') === false) { return; } $tokens = $phpcsFile->getTokens(); $scopePtr = Scopes::validDirectScope($phpcsFile, $stackPtr, Tokens::$ooScopeTokens); if ($scopePtr === false) { // Function, not method. return; } $properties = FunctionDeclarations::getProperties($phpcsFile, $stackPtr); if ($properties['scope'] !== 'private' || $properties['is_abstract'] !== true) { // Not an abstract private method. return; } if ($tokens[$scopePtr]['code'] === \T_TRAIT) { if (ScannedCode::shouldRunOnOrBelow('7.4') === true) { $phpcsFile->addError( 'Traits cannot declare "abstract private" methods in PHP 7.4 or below', $stackPtr, 'InTrait' ); } return; } // Not a trait. $phpcsFile->addError( 'Abstract methods cannot be declared as private since PHP 5.1', $stackPtr, 'Found' ); } }