3
* Squiz_Sniffs_WhiteSpace_PropertyLabelSpacingSniff.
8
* @package PHP_CodeSniffer
9
* @author Greg Sherwood <gsherwood@squiz.net>
10
* @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
11
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
12
* @link http://pear.php.net/package/PHP_CodeSniffer
16
* Squiz_Sniffs_WhiteSpace_PropertyLabelSpacingSniff.
18
* Ensures that the colon in a property or label definition has a single
19
* space after it and no space before it.
22
* @package PHP_CodeSniffer
23
* @author Greg Sherwood <gsherwood@squiz.net>
24
* @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
25
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
26
* @version Release: 1.5.3
27
* @link http://pear.php.net/package/PHP_CodeSniffer
29
class Squiz_Sniffs_WhiteSpace_PropertyLabelSpacingSniff implements PHP_CodeSniffer_Sniff
33
* A list of tokenizers this sniff supports.
37
public $supportedTokenizers = array('JS');
41
* Returns an array of tokens this test wants to listen for.
45
public function register()
56
* Processes this test, when one of its tokens is encountered.
58
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
59
* @param int $stackPtr The position of the current token
60
* in the stack passed in $tokens.
64
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
66
$tokens = $phpcsFile->getTokens();
68
$colon = $phpcsFile->findNext(T_COLON, ($stackPtr + 1));
70
if ($colon !== ($stackPtr + 1)) {
71
$error = 'There must be no space before the colon in a property/label declaration';
72
$phpcsFile->addError($error, $stackPtr, 'Before');
75
if ($tokens[($colon + 1)]['code'] !== T_WHITESPACE || $tokens[($colon + 1)]['content'] !== ' ') {
76
$error = 'There must be a single space after the colon in a property/label declaration';
77
$phpcsFile->addError($error, $stackPtr, 'After');