NamespaceSniff.php in Coder 8.2
Same filename and directory in other branches
Namespace
Drupal\Sniffs\WhiteSpaceFile
coder_sniffer/Drupal/Sniffs/WhiteSpace/NamespaceSniff.phpView source
<?php
/**
* \Drupal\Sniffs\WhiteSpace\NamespaceSniff.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
namespace Drupal\Sniffs\WhiteSpace;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
/**
* Checks that there is exactly one space after the namespace keyword.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class NamespaceSniff implements Sniff {
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register() {
return array(
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, ' ');
}
}
}
}
//end class
Classes
Name | Description |
---|---|
NamespaceSniff | Checks that there is exactly one space after the namespace keyword. |