PHP_CodeSniffer
[ class tree: PHP_CodeSniffer ] [ index: PHP_CodeSniffer ] [ all elements ]

Source for file NoSilencedErrorsSniff.php

Documentation is available at NoSilencedErrorsSniff.php

  1. <?php
  2. /**
  3.  * Throws an error or warning when any code prefixed with an asperand is encountered.
  4.  *
  5.  * <code>
  6.  *  if (@in_array($array, $needle))
  7.  *  {
  8.  *      doSomething();
  9.  *  }
  10.  * </code>
  11.  *
  12.  * @author    Andy Brockhurst <abrock@yahoo-inc.com>
  13.  * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
  14.  * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
  15.  */
  16.  
  17. namespace PHP_CodeSniffer\Standards\Generic\Sniffs\PHP;
  18.  
  19. use PHP_CodeSniffer\Sniffs\Sniff;
  20. use PHP_CodeSniffer\Files\File;
  21.  
  22. class NoSilencedErrorsSniff implements Sniff
  23. {
  24.  
  25.     /**
  26.      * If true, an error will be thrown; otherwise a warning.
  27.      *
  28.      * @var boolean 
  29.      */
  30.     public $error = false;
  31.  
  32.  
  33.     /**
  34.      * Returns an array of tokens this test wants to listen for.
  35.      *
  36.      * @return array 
  37.      */
  38.     public function register()
  39.     {
  40.         return array(T_ASPERAND);
  41.  
  42.     }//end register()
  43.  
  44.  
  45.     /**
  46.      * Processes this test, when one of its tokens is encountered.
  47.      *
  48.      * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
  49.      * @param int                         $stackPtr  The position of the current token
  50.      *                                                in the stack passed in $tokens.
  51.      *
  52.      * @return void 
  53.      */
  54.     public function process(File $phpcsFile$stackPtr)
  55.     {
  56.         $error 'Silencing errors is forbidden';
  57.         if ($this->error === true{
  58.             $error 'Silencing errors is forbidden';
  59.             $phpcsFile->addError($error$stackPtr'Forbidden');
  60.         else {
  61.             $error 'Silencing errors is discouraged';
  62.             $phpcsFile->addWarning($error$stackPtr'Discouraged');
  63.         }
  64.  
  65.     }//end process()
  66.  
  67.  
  68. }//end class

Documentation generated on Mon, 11 Mar 2019 15:27:39 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.