function GlobalFunctionSniff::process
Same name in this branch
- 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
Namespace
PHP_CodeSniffer\Standards\Squiz\Sniffs\FunctionsCode
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);
}
}
}