class HereNowdocIdentifierSpacingSniff
Hierarchy
- class \PHP_CodeSniffer\Standards\Generic\Sniffs\WhiteSpace\HereNowdocIdentifierSpacingSniff implements \PHP_CodeSniffer\Sniffs\Sniff
Expanded class hierarchy of HereNowdocIdentifierSpacingSniff
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Standards/ Generic/ Sniffs/ WhiteSpace/ HereNowdocIdentifierSpacingSniff.php, line 15
Namespace
PHP_CodeSniffer\Standards\Generic\Sniffs\WhiteSpaceView source
class HereNowdocIdentifierSpacingSniff implements Sniff {
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array<int|string>
*/
public function register() {
return [
T_START_HEREDOC,
T_START_NOWDOC,
];
}
//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 (strpos($tokens[$stackPtr]['content'], ' ') === false && strpos($tokens[$stackPtr]['content'], "\t") === false) {
// Nothing to do.
$phpcsFile->recordMetric($stackPtr, 'Heredoc/nowdoc identifier', 'no space between <<< and ID');
return;
}
$phpcsFile->recordMetric($stackPtr, 'Heredoc/nowdoc identifier', 'space between <<< and ID');
$error = 'There should be no space between the <<< and the heredoc/nowdoc identifier string';
$data = [
$tokens[$stackPtr]['content'],
];
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceFound', $data);
if ($fix === true) {
$replacement = str_replace([
' ',
"\t",
], '', $tokens[$stackPtr]['content']);
$phpcsFile->fixer
->replaceToken($stackPtr, $replacement);
}
}
//end process()
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
HereNowdocIdentifierSpacingSniff::process | public | function | Processes this test, when one of its tokens is encountered. | Overrides Sniff::process |
HereNowdocIdentifierSpacingSniff::register | public | function | Returns an array of tokens this test wants to listen for. | Overrides Sniff::register |