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 https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence 11 * @link http://pear.php.net/package/PHP_CodeSniffer 12 */ 13 14/** 15 * Generic_Sniffs_PHP_NoSilencedErrorsSniff. 16 * 17 * Throws an error or warning when any code prefixed with an asperand is encountered. 18 * 19 * <code> 20 * if (@in_array($array, $needle)) 21 * { 22 * doSomething(); 23 * } 24 * </code> 25 * 26 * @category PHP 27 * @package PHP_CodeSniffer 28 * @author Andy Brockhurst <abrock@yahoo-inc.com> 29 * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence 30 * @version Release: @package_version@ 31 * @link http://pear.php.net/package/PHP_CodeSniffer 32 */ 33class Generic_Sniffs_PHP_NoSilencedErrorsSniff implements PHP_CodeSniffer_Sniff 34{ 35 36 /** 37 * If true, an error will be thrown; otherwise a warning. 38 * 39 * @var bool 40 */ 41 public $error = false; 42 43 44 /** 45 * Returns an array of tokens this test wants to listen for. 46 * 47 * @return array 48 */ 49 public function register() 50 { 51 return array(T_ASPERAND); 52 53 }//end register() 54 55 56 /** 57 * Processes this test, when one of its tokens is encountered. 58 * 59 * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. 60 * @param int $stackPtr The position of the current token 61 * in the stack passed in $tokens. 62 * 63 * @return void 64 */ 65 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 66 { 67 $error = 'Silencing errors is forbidden'; 68 if ($this->error === true) { 69 $error = 'Silencing errors is forbidden'; 70 $phpcsFile->addError($error, $stackPtr, 'Forbidden'); 71 } else { 72 $error = 'Silencing errors is discouraged'; 73 $phpcsFile->addWarning($error, $stackPtr, 'Discouraged'); 74 } 75 76 }//end process() 77 78 79}//end class 80