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: MethodScopeSniff.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_AbstractScopeSniff', true) === false) {
18
    throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractScopeSniff 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_MethodScopeSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff
34
{
35
 
36
 
37
    /**
38
     * Constructs a Squiz_Sniffs_Scope_MethodScopeSniff.
39
     */
40
    public function __construct()
41
    {
42
        parent::__construct(array(T_CLASS, T_INTERFACE), array(T_FUNCTION));
43
 
44
    }//end __construct()
45
 
46
 
47
    /**
48
     * Processes the function tokens within the class.
49
     *
50
     * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
51
     * @param int                  $stackPtr  The position where the token was found.
52
     * @param int                  $currScope The current scope opener token.
53
     *
54
     * @return void
55
     */
56
    protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
57
    {
58
        $tokens = $phpcsFile->getTokens();
59
 
60
        $modifier = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$scopeModifiers, $stackPtr);
61
        if (($modifier === false) || ($tokens[$modifier]['line'] !== $tokens[$stackPtr]['line'])) {
62
            $name  = $phpcsFile->findNext(T_STRING, ($stackPtr + 1));
63
            $name  = $tokens[$name]['content'];
64
            $error = "No scope modifier specified for function \"$name\"";
65
            $phpcsFile->addError($error, $stackPtr);
66
        }
67
 
68
    }//end processTokenWithinScope()
69
 
70
 
71
}//end class
72
 
73
?>