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

Source for file ObjectMemberCommaSniff.php

Documentation is available at ObjectMemberCommaSniff.php

  1. <?php
  2. /**
  3.  * Ensures the last member of an object is not followed by a comma.
  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\Objects;
  11.  
  12. use PHP_CodeSniffer\Sniffs\Sniff;
  13. use PHP_CodeSniffer\Files\File;
  14. use PHP_CodeSniffer\Util\Tokens;
  15.  
  16. class ObjectMemberCommaSniff implements Sniff
  17. {
  18.  
  19.     /**
  20.      * A list of tokenizers this sniff supports.
  21.      *
  22.      * @var array 
  23.      */
  24.     public $supportedTokenizers = array('JS');
  25.  
  26.  
  27.     /**
  28.      * Registers the token types that this sniff wishes to listen to.
  29.      *
  30.      * @return array 
  31.      */
  32.     public function register()
  33.     {
  34.         return array(T_CLOSE_OBJECT);
  35.  
  36.     }//end register()
  37.  
  38.  
  39.     /**
  40.      * Process the tokens that this sniff is listening for.
  41.      *
  42.      * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found.
  43.      * @param int                         $stackPtr  The position in the stack where
  44.      *                                                the token was found.
  45.      *
  46.      * @return void 
  47.      */
  48.     public function process(File $phpcsFile$stackPtr)
  49.     {
  50.         $tokens $phpcsFile->getTokens();
  51.  
  52.         $prev $phpcsFile->findPrevious(Tokens::$emptyTokens($stackPtr - 1)nulltrue);
  53.         if ($tokens[$prev]['code'=== T_COMMA{
  54.             $error 'Last member of object must not be followed by a comma';
  55.             $fix   $phpcsFile->addFixableError($error$prev'Missing');
  56.             if ($fix === true{
  57.                 $phpcsFile->fixer->replaceToken($prev'');
  58.             }
  59.         }
  60.  
  61.     }//end process()
  62.  
  63.  
  64. }//end class

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