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

Breadcrumb

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

function GlobalFunctionSniff::process

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

Processes this test, when one of its tokens is encountered.

Parameters

\PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.:

int $stackPtr The position of the current token in the: stack passed in $tokens.

Return value

void

Overrides Sniff::process

File

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

Class

GlobalFunctionSniff

Namespace

PHP_CodeSniffer\Standards\Squiz\Sniffs\Functions

Code

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);
        }
    }
}
RSS feed
Powered by Drupal