Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * Verifies that class members have scope modifiers.
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: MemberVarScopeSniff.php 240383 2007-07-27 05:38:59Z squiz $
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 have scope modifiers.
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.2.1
31
 * @link      http://pear.php.net/package/PHP_CodeSniffer
32
 */
33
class Squiz_Sniffs_Scope_MemberVarScopeSniff 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
        $modifier = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$scopeModifiers, $stackPtr);
50
 
51
        if (($modifier === false) || ($tokens[$modifier]['line'] !== $tokens[$stackPtr]['line'])) {
52
            $var   = $tokens[$stackPtr]['content'];
53
            $error = "Scope modifier not specified for member variable \"$var\"";
54
            $phpcsFile->addError($error, $stackPtr);
55
        }
56
 
57
    }//end processMemberVar()
58
 
59
 
60
    /**
61
     * Processes normal variables.
62
     *
63
     * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
64
     * @param int                  $stackPtr  The position where the token was found.
65
     *
66
     * @return void
67
     */
68
    protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
69
    {
70
        // We don't care about normal variables.
71
        return;
72
 
73
    }//end processVariable()
74
 
75
 
76
    /**
77
     * Processes variables in double quoted strings.
78
     *
79
     * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
80
     * @param int                  $stackPtr  The position where the token was found.
81
     *
82
     * @return void
83
     */
84
    protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
85
    {
86
        // We don't care about normal variables.
87
        return;
88
 
89
    }//end processVariableInString()
90
 
91
 
92
}//end class
93
 
94
?>