Subversion Repositories Applications.framework

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5 aurelien 1
<?php
2
/**
3
 * Generic_Sniffs_PHP_NoSilencedErrorsSniff
4
 *
5
 * PHP version 5
6
 *
7
 * @category PHP
8
 * @package  PHP_CodeSniffer
9
 * @author   Andy Brockhurst <abrock@yahoo-inc.com>
10
 * @license  http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
11
 * @version  CVS: $Id: NoSilencedErrorsSniff.php,v 1.1 2008/12/03 04:42:07 squiz Exp $
12
 * @link     http://pear.php.net/package/PHP_CodeSniffer
13
 */
14
 
15
/**
16
 * Generic_Sniffs_PHP_NoSilencedErrorsSniff.
17
 *
18
 * Throws an error or warning when any code prefixed with an asperand is encountered.
19
 *
20
 * <code>
21
 *  if (@in_array($array, $needle))
22
 *  {
23
 *      doSomething();
24
 *  }
25
 * </code>
26
 *
27
 * @category PHP
28
 * @package  PHP_CodeSniffer
29
 * @author   Andy Brockhurst <abrock@yahoo-inc.com>
30
 * @license  http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
31
 * @version  Release: 1.2.0RC1
32
 * @link     http://pear.php.net/package/PHP_CodeSniffer
33
 */
34
class Generic_Sniffs_PHP_NoSilencedErrorsSniff implements PHP_CodeSniffer_Sniff
35
{
36
 
37
    /**
38
     * If true, an error will be thrown; otherwise a warning.
39
     *
40
     * @var bool
41
     */
42
    protected $error = false;
43
 
44
 
45
    /**
46
     * Returns an array of tokens this test wants to listen for.
47
     *
48
     * @return array
49
     */
50
    public function register()
51
    {
52
        return array(T_ASPERAND);
53
 
54
    }//end register()
55
 
56
 
57
    /**
58
     * Processes this test, when one of its tokens is encountered.
59
     *
60
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
61
     * @param int                  $stackPtr  The position of the current token
62
     *                                        in the stack passed in $tokens.
63
     *
64
     * @return void
65
     */
66
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
67
    {
68
        $error = 'Silencing errors is ';
69
        if ($this->error === true) {
70
            $error .= 'forbidden';
71
            $phpcsFile->addError($error, $stackPtr);
72
        } else {
73
            $error .= 'discouraged';
74
            $phpcsFile->addWarning($error, $stackPtr);
75
        }
76
 
77
    }//end process()
78
 
79
 
80
}//end class
81
 
82
?>