function CompoundNamespaceDepthSniff::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/ PSR12/ Sniffs/ Namespaces/ CompoundNamespaceDepthSniff.php, line 47
Class
Namespace
PHP_CodeSniffer\Standards\PSR12\Sniffs\NamespacesCode
public function process(File $phpcsFile, $stackPtr) {
$this->maxDepth = (int) $this->maxDepth;
$tokens = $phpcsFile->getTokens();
$end = $phpcsFile->findNext(T_CLOSE_USE_GROUP, $stackPtr + 1);
if ($end === false) {
return;
}
$depth = 1;
for ($i = $stackPtr + 1; $i <= $end; $i++) {
if ($tokens[$i]['code'] === T_NS_SEPARATOR) {
$depth++;
continue;
}
if ($i === $end || $tokens[$i]['code'] === T_COMMA) {
// End of a namespace.
if ($depth > $this->maxDepth) {
$error = 'Compound namespaces cannot have a depth more than %s';
$data = [
$this->maxDepth,
];
$phpcsFile->addError($error, $i, 'TooDeep', $data);
}
$depth = 1;
}
}
}