Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. GlobalFunctionSniff.php

class GlobalFunctionSniff

Same name in this branch
  1. 11.1.x vendor/drupal/coder/coder_sniffer/DrupalPractice/Sniffs/Objects/GlobalFunctionSniff.php \DrupalPractice\Sniffs\Objects\GlobalFunctionSniff

Hierarchy

  • class \PHP_CodeSniffer\Standards\Squiz\Sniffs\Functions\GlobalFunctionSniff implements \PHP_CodeSniffer\Sniffs\Sniff

Expanded class hierarchy of GlobalFunctionSniff

File

vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Functions/GlobalFunctionSniff.php, line 15

Namespace

PHP_CodeSniffer\Standards\Squiz\Sniffs\Functions
View source
class GlobalFunctionSniff implements Sniff {
    
    /**
     * Returns an array of tokens this test wants to listen for.
     *
     * @return array<int|string>
     */
    public function register() {
        return [
            T_FUNCTION,
        ];
    }
    
    //end register()
    
    /**
     * Processes this test, when one of its tokens is encountered.
     *
     * @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 (empty($tokens[$stackPtr]['conditions']) === true) {
            $functionName = $phpcsFile->getDeclarationName($stackPtr);
            if ($functionName === null) {
                return;
            }
            // Special exception for __autoload as it needs to be global.
            if ($functionName !== '__autoload') {
                $error = 'Consider putting global function "%s" in a static class';
                $data = [
                    $functionName,
                ];
                $phpcsFile->addWarning($error, $stackPtr, 'Found', $data);
            }
        }
    }
    
    //end process()

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
GlobalFunctionSniff::process public function Processes this test, when one of its tokens is encountered. Overrides Sniff::process
GlobalFunctionSniff::register public function Returns an array of tokens this test wants to listen for. Overrides Sniff::register
RSS feed
Powered by Drupal