Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * Squiz_Sniffs_Objects_ObjectInstantiationSniff.
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PHP_CodeSniffer
9
 * @author    Greg Sherwood <gsherwood@squiz.net>
10
 * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
11
 * @license   http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
12
 * @version   CVS: $Id: ObjectMemberCommaSniff.php 265600 2008-08-29 06:46:03Z squiz $
13
 * @link      http://pear.php.net/package/PHP_CodeSniffer
14
 */
15
 
16
/**
17
 * Squiz_Sniffs_Objects_ObjectInstantiationSniff.
18
 *
19
 * Ensures objects are assigned to a variable when instantiated.
20
 *
21
 * @category  PHP
22
 * @package   PHP_CodeSniffer
23
 * @author    Greg Sherwood <gsherwood@squiz.net>
24
 * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
25
 * @license   http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
26
 * @version   Release: 1.2.1
27
 * @link      http://pear.php.net/package/PHP_CodeSniffer
28
 */
29
class Squiz_Sniffs_Objects_ObjectMemberCommaSniff implements PHP_CodeSniffer_Sniff
30
{
31
 
32
    /**
33
     * A list of tokenizers this sniff supports.
34
     *
35
     * @var array
36
     */
37
    public $supportedTokenizers = array('JS');
38
 
39
 
40
    /**
41
     * Registers the token types that this sniff wishes to listen to.
42
     *
43
     * @return array
44
     */
45
    public function register()
46
    {
47
        return array(T_CLOSE_CURLY_BRACKET);
48
 
49
    }//end register()
50
 
51
 
52
    /**
53
     * Process the tokens that this sniff is listening for.
54
     *
55
     * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
56
     * @param int                  $stackPtr  The position in the stack where
57
     *                                        the token was found.
58
     *
59
     * @return void
60
     */
61
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
62
    {
63
        $tokens = $phpcsFile->getTokens();
64
 
65
        // Only interested in orphaned braces (which are objects)
66
        // and object definitions.
67
        if (isset($tokens[$stackPtr]['scope_condition']) === true) {
68
            $condition = $tokens[$stackPtr]['scope_condition'];
69
            if ($tokens[$condition]['code'] !== T_OBJECT) {
70
                return;
71
            }
72
        }
73
 
74
        $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
75
        if ($tokens[$prev]['code'] === T_COMMA) {
76
            $error = 'Last member of object must not be followed by a comma';
77
            $phpcsFile->addError($error, $prev);
78
        }
79
 
80
    }//end process()
81
 
82
 
83
}//end class
84
 
85
?>