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

Source for file EmptyCatchCommentSniff.php

Documentation is available at EmptyCatchCommentSniff.php

  1. <?php
  2. /**
  3.  * Checks for empty catch clause without a comment.
  4.  *
  5.  * @author    Greg Sherwood <gsherwood@squiz.net>
  6.  * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
  7.  * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
  8.  */
  9.  
  10. namespace PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting;
  11.  
  12. use PHP_CodeSniffer\Sniffs\Sniff;
  13. use PHP_CodeSniffer\Files\File;
  14.  
  15. class EmptyCatchCommentSniff implements Sniff
  16. {
  17.  
  18.  
  19.     /**
  20.      * Returns an array of tokens this test wants to listen for.
  21.      *
  22.      * @return array 
  23.      */
  24.     public function register()
  25.     {
  26.         return array(T_CATCH);
  27.  
  28.     }//end register()
  29.  
  30.  
  31.     /**
  32.      * Processes this test, when one of its tokens is encountered.
  33.      *
  34.      * @param \PHP_CodeSniffer\Files\File $phpcsFile All the tokens found in the document.
  35.      * @param int                         $stackPtr  The position of the current token in the
  36.      *                                                stack passed in $tokens.
  37.      *
  38.      * @return void 
  39.      */
  40.     public function process(File $phpcsFile$stackPtr)
  41.     {
  42.         $tokens $phpcsFile->getTokens();
  43.  
  44.         $scopeStart   $tokens[$stackPtr]['scope_opener'];
  45.         $firstContent $phpcsFile->findNext(T_WHITESPACE($scopeStart + 1)$tokens[$stackPtr]['scope_closer']true);
  46.  
  47.         if ($firstContent === false{
  48.             $error 'Empty CATCH statement must have a comment to explain why the exception is not handled';
  49.             $phpcsFile->addError($error$scopeStart'Missing');
  50.         }
  51.  
  52.     }//end process()
  53.  
  54.  
  55. }//end class

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