~ubuntu-branches/ubuntu/saucy/php-codesniffer/saucy

« back to all changes in this revision

Viewing changes to PHP_CodeSniffer-1.1.0/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php

  • Committer: Package Import Robot
  • Author(s): Thomas Goirand
  • Date: 2012-05-31 16:37:24 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20120531163724-u6aiaubu8ks5dh5z
Tags: 1.3.4-0.1
* Non-maintainer upload.
* New upstream release (Closes: #599617, #634825).
* Swtiched debian/copyright to format 1.0 (rewrite was needed anyway, as the
upstream license changed).
* Switched package to pkg-php-tools and debhelper 8 sequencer.
* Now running unit tests at build time (so depends on phpunit (>= 3.6)).
* Section is now PHP.
* Added missing Build-Depends-Indep: php-pear.
* Added missing ${misc:Depends}.
* Added Vcs fields.
* Added homepage field.
* Reviewed short and long description.
* Added dependency on php-timer.
* Standards-Version: is now 3.9.3 (lots of changes, see above...).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/**
3
 
 * Verifies that class members are spaced correctly.
4
 
 *
5
 
 * PHP version 5
6
 
 *
7
 
 * @category  PHP
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
15
 
 */
16
 
 
17
 
if (class_exists('PHP_CodeSniffer_Standards_AbstractVariableSniff', true) === false) {
18
 
    throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractVariableSniff not found');
19
 
}
20
 
 
21
 
/**
22
 
 * Verifies that class members are spaced correctly.
23
 
 *
24
 
 * @category  PHP
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
32
 
 */
33
 
class Squiz_Sniffs_WhiteSpace_MemberVarSpacingSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff
34
 
{
35
 
 
36
 
 
37
 
    /**
38
 
     * Processes the function tokens within the class.
39
 
     *
40
 
     * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
41
 
     * @param int                  $stackPtr  The position where the token was found.
42
 
     *
43
 
     * @return void
44
 
     */
45
 
    protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
46
 
    {
47
 
        $tokens = $phpcsFile->getTokens();
48
 
 
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) {
53
 
                // Skip comments.
54
 
                continue;
55
 
            } else if (strpos($tokens[$i]['content'], $phpcsFile->eolChar) === false) {
56
 
                // Not the end of the line.
57
 
                continue;
58
 
            } else {
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) {
63
 
                    continue;
64
 
                }
65
 
 
66
 
                $prevLineToken = $i;
67
 
                break;
68
 
            }
69
 
        }
70
 
 
71
 
        if (is_null($prevLineToken) === true) {
72
 
            // Never found the previous line, which means
73
 
            // there are 0 blank lines before the member var.
74
 
            $foundLines = 0;
75
 
        } else {
76
 
            $prevContent = $phpcsFile->findPrevious(array(T_WHITESPACE, T_DOC_COMMENT), $prevLineToken, null, true);
77
 
            $foundLines  = ($tokens[$prevLineToken]['line'] - $tokens[$prevContent]['line']);
78
 
        }//end if
79
 
 
80
 
        if ($foundLines !== 1) {
81
 
            $phpcsFile->addError("Expected 1 blank line before member var; $foundLines found", $stackPtr);
82
 
        }
83
 
 
84
 
    }//end processMemberVar()
85
 
 
86
 
 
87
 
    /**
88
 
     * Processes normal variables.
89
 
     *
90
 
     * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
91
 
     * @param int                  $stackPtr  The position where the token was found.
92
 
     *
93
 
     * @return void
94
 
     */
95
 
    protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
96
 
    {
97
 
        // We don't care about normal variables.
98
 
        return;
99
 
 
100
 
    }//end processVariable()
101
 
 
102
 
 
103
 
    /**
104
 
     * Processes variables in double quoted strings.
105
 
     *
106
 
     * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
107
 
     * @param int                  $stackPtr  The position where the token was found.
108
 
     *
109
 
     * @return void
110
 
     */
111
 
    protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
112
 
    {
113
 
        // We don't care about normal variables.
114
 
        return;
115
 
 
116
 
    }//end processVariableInString()
117
 
 
118
 
 
119
 
}//end class
120
 
 
121
 
?>