3
* Verifies that class members are spaced correctly.
8
* @package PHP_CodeSniffer
9
* @author Greg Sherwood <gsherwood@squiz.net>
10
* @author Marc McIntyre <mmcintyre@squiz.net>
11
* @copyright 2006-2012 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
16
if (class_exists('PHP_CodeSniffer_Standards_AbstractVariableSniff', true) === false) {
17
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractVariableSniff not found');
21
* Verifies that class members are spaced correctly.
24
* @package PHP_CodeSniffer
25
* @author Greg Sherwood <gsherwood@squiz.net>
26
* @author Marc McIntyre <mmcintyre@squiz.net>
27
* @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600)
28
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
29
* @version Release: 1.5.0RC2
30
* @link http://pear.php.net/package/PHP_CodeSniffer
32
class Squiz_Sniffs_WhiteSpace_MemberVarSpacingSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff
37
* Processes the function tokens within the class.
39
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
40
* @param int $stackPtr The position where the token was found.
44
protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
46
$tokens = $phpcsFile->getTokens();
48
// There needs to be 1 blank line before the var, not counting comments.
49
$prevLineToken = null;
50
for ($i = ($stackPtr - 1); $i > 0; $i--) {
51
if (in_array($tokens[$i]['code'], PHP_CodeSniffer_Tokens::$commentTokens) === true) {
54
} else if (strpos($tokens[$i]['content'], $phpcsFile->eolChar) === false) {
55
// Not the end of the line.
58
// If this is a WHITESPACE token, and the token right before
59
// it is a DOC_COMMENT, then it is just the newline after the
60
// member var's comment, and can be skipped.
61
if ($tokens[$i]['code'] === T_WHITESPACE && in_array($tokens[($i - 1)]['code'], PHP_CodeSniffer_Tokens::$commentTokens) === true) {
70
if (is_null($prevLineToken) === true) {
71
// Never found the previous line, which means
72
// there are 0 blank lines before the member var.
75
$prevContent = $phpcsFile->findPrevious(array(T_WHITESPACE, T_DOC_COMMENT), $prevLineToken, null, true);
76
$foundLines = ($tokens[$prevLineToken]['line'] - $tokens[$prevContent]['line']);
79
if ($foundLines !== 1) {
80
$error = 'Expected 1 blank line before member var; %s found';
81
$data = array($foundLines);
82
$phpcsFile->addError($error, $stackPtr, 'After', $data);
85
}//end processMemberVar()
89
* Processes normal variables.
91
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
92
* @param int $stackPtr The position where the token was found.
96
protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
98
// We don't care about normal variables.
100
}//end processVariable()
104
* Processes variables in double quoted strings.
106
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
107
* @param int $stackPtr The position where the token was found.
111
protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
113
// We don't care about normal variables.
115
}//end processVariableInString()