function InnerFunctionsSniff::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/ PHP/ InnerFunctionsSniff.php, line 41
Class
Namespace
PHP_CodeSniffer\Standards\Squiz\Sniffs\PHPCode
public function process(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile->getTokens();
if (isset($tokens[$stackPtr]['conditions']) === false) {
return;
}
$conditions = $tokens[$stackPtr]['conditions'];
$reversedConditions = array_reverse($conditions, true);
$outerFuncToken = null;
foreach ($reversedConditions as $condToken => $condition) {
if ($condition === T_FUNCTION || $condition === T_CLOSURE) {
$outerFuncToken = $condToken;
break;
}
if (array_key_exists($condition, Tokens::$ooScopeTokens) === true) {
// Ignore methods in OOP structures defined within functions.
return;
}
}
if ($outerFuncToken === null) {
// Not a nested function.
return;
}
$error = 'The use of inner functions is forbidden';
$phpcsFile->addError($error, $stackPtr, 'NotAllowed');
}