class NamespaceSniff in Coder 8.3.x
Same name and namespace in other branches
- 8.3 coder_sniffer/Drupal/Sniffs/WhiteSpace/NamespaceSniff.php \Drupal\Sniffs\WhiteSpace\NamespaceSniff
- 8.2 coder_sniffer/Drupal/Sniffs/WhiteSpace/NamespaceSniff.php \Drupal\Sniffs\WhiteSpace\NamespaceSniff
Checks that there is exactly one space after the namespace keyword.
@category PHP @package PHP_CodeSniffer @link http://pear.php.net/package/PHP_CodeSniffer
Hierarchy
- class \Drupal\Sniffs\WhiteSpace\NamespaceSniff implements \PHP_CodeSniffer\Sniffs\Sniff
Expanded class hierarchy of NamespaceSniff
File
- coder_sniffer/
Drupal/ Sniffs/ WhiteSpace/ NamespaceSniff.php, line 22
Namespace
Drupal\Sniffs\WhiteSpaceView source
class NamespaceSniff implements Sniff {
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array<int|string>
*/
public function register() {
return [
T_NAMESPACE,
];
}
//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile
->getTokens();
if ($tokens[$stackPtr + 1]['content'] !== ' ') {
$error = 'There must be exactly one space after the namepace keyword';
$fix = $phpcsFile
->addFixableError($error, $stackPtr + 1, 'OneSpace');
if ($fix === true) {
$phpcsFile->fixer
->replaceToken($stackPtr + 1, ' ');
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
NamespaceSniff:: |
public | function | Processes this test, when one of its tokens is encountered. | |
NamespaceSniff:: |
public | function | Returns an array of tokens this test wants to listen for. |