function SelfMemberReferenceSniff::getNamespaceOfScope
Returns the namespace declaration of a file.
Parameters
\PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.:
int $stackPtr The position where the search for the: namespace declaration will start.
Return value
string
1 call to SelfMemberReferenceSniff::getNamespaceOfScope()
- SelfMemberReferenceSniff::processTokenWithinScope in vendor/
squizlabs/ php_codesniffer/ src/ Standards/ Squiz/ Sniffs/ Classes/ SelfMemberReferenceSniff.php - Processes the function tokens within the class.
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Standards/ Squiz/ Sniffs/ Classes/ SelfMemberReferenceSniff.php, line 222
Class
Namespace
PHP_CodeSniffer\Standards\Squiz\Sniffs\ClassesCode
protected function getNamespaceOfScope(File $phpcsFile, $stackPtr) {
$namespace = '\\';
$tokens = $phpcsFile->getTokens();
while (($namespaceDeclaration = $phpcsFile->findPrevious(T_NAMESPACE, $stackPtr)) !== false) {
$nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, $namespaceDeclaration + 1, null, true);
if ($tokens[$nextNonEmpty]['code'] === T_NS_SEPARATOR) {
// Namespace operator. Ignore.
$stackPtr = $namespaceDeclaration - 1;
continue;
}
$endOfNamespaceDeclaration = $phpcsFile->findNext([
T_SEMICOLON,
T_OPEN_CURLY_BRACKET,
T_CLOSE_TAG,
], $namespaceDeclaration);
$namespace = $this->getDeclarationNameWithNamespace($phpcsFile->getTokens(), $endOfNamespaceDeclaration - 1);
break;
}
return $namespace;
}