3
* Squiz_Sniffs_WhiteSpace_LanguageConstructSpacingSniff.
8
* @package PHP_CodeSniffer
9
* @author Greg Sherwood <gsherwood@squiz.net>
10
* @author Marc McIntyre <mmcintyre@squiz.net>
11
* @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
12
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
13
* @link http://pear.php.net/package/PHP_CodeSniffer
17
* Squiz_Sniffs_WhiteSpace_LanguageConstructSpacingSniff.
19
* Ensures all language constructs (without brackets) contain a
20
* single space between themselves and their content.
23
* @package PHP_CodeSniffer
24
* @author Greg Sherwood <gsherwood@squiz.net>
25
* @author Marc McIntyre <mmcintyre@squiz.net>
26
* @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
27
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
28
* @version Release: 1.5.4
29
* @link http://pear.php.net/package/PHP_CodeSniffer
31
class Squiz_Sniffs_WhiteSpace_LanguageConstructSpacingSniff implements PHP_CodeSniffer_Sniff
36
* Returns an array of tokens this test wants to listen for.
40
public function register()
57
* Processes this test, when one of its tokens is encountered.
59
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
60
* @param int $stackPtr The position of the current token in
61
* the stack passed in $tokens.
65
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
67
$tokens = $phpcsFile->getTokens();
69
if ($tokens[($stackPtr + 1)]['code'] === T_SEMICOLON) {
70
// No content for this language construct.
74
if ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE) {
75
$content = $tokens[($stackPtr + 1)]['content'];
76
$contentLength = strlen($content);
77
if ($contentLength !== 1) {
78
$error = 'Language constructs must be followed by a single space; expected 1 space but found %s';
79
$data = array($contentLength);
80
$phpcsFile->addError($error, $stackPtr, 'IncorrectSingle', $data);
83
$error = 'Language constructs must be followed by a single space; expected "%s" but found "%s"';
85
$tokens[$stackPtr]['content'].' '.$tokens[($stackPtr + 1)]['content'],
86
$tokens[$stackPtr]['content'].$tokens[($stackPtr + 1)]['content'],
88
$phpcsFile->addError($error, $stackPtr, 'Incorrect', $data);