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 Squiz Pty Ltd (ABN 77 084 670 600)
12
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
13
* @version CVS: $Id: MemberVarSpacingSniff.php,v 1.4 2007/07/27 05:36:26 squiz Exp $
14
* @link http://pear.php.net/package/PHP_CodeSniffer
17
if (class_exists('PHP_CodeSniffer_Standards_AbstractVariableSniff', true) === false) {
18
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractVariableSniff not found');
22
* Verifies that class members are spaced correctly.
25
* @package PHP_CodeSniffer
26
* @author Greg Sherwood <gsherwood@squiz.net>
27
* @author Marc McIntyre <mmcintyre@squiz.net>
28
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
29
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
30
* @version Release: 1.1.0
31
* @link http://pear.php.net/package/PHP_CodeSniffer
33
class Squiz_Sniffs_WhiteSpace_MemberVarSpacingSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff
38
* Processes the function tokens within the class.
40
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
41
* @param int $stackPtr The position where the token was found.
45
protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
47
$tokens = $phpcsFile->getTokens();
49
// There needs to be 1 blank line before the var, not counting comments.
50
$prevLineToken = null;
51
for ($i = ($stackPtr - 1); $i > 0; $i--) {
52
if (in_array($tokens[$i]['code'], PHP_CodeSniffer_Tokens::$commentTokens) === true) {
55
} else if (strpos($tokens[$i]['content'], $phpcsFile->eolChar) === false) {
56
// Not the end of the line.
59
// If this is a WHITESPACE token, and the token right before
60
// it is a DOC_COMMENT, then it is just the newline after the
61
// member var's comment, and can be skipped.
62
if ($tokens[$i]['code'] === T_WHITESPACE && in_array($tokens[($i - 1)]['code'], PHP_CodeSniffer_Tokens::$commentTokens) === true) {
71
if (is_null($prevLineToken) === true) {
72
// Never found the previous line, which means
73
// there are 0 blank lines before the member var.
76
$prevContent = $phpcsFile->findPrevious(array(T_WHITESPACE, T_DOC_COMMENT), $prevLineToken, null, true);
77
$foundLines = ($tokens[$prevLineToken]['line'] - $tokens[$prevContent]['line']);
80
if ($foundLines !== 1) {
81
$phpcsFile->addError("Expected 1 blank line before member var; $foundLines found", $stackPtr);
84
}//end processMemberVar()
88
* Processes normal variables.
90
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
91
* @param int $stackPtr The position where the token was found.
95
protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
97
// 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.
116
}//end processVariableInString()