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

Source for file FirebugConsoleSniff.php

Documentation is available at FirebugConsoleSniff.php

  1. <?php
  2. /**
  3.  * Ensures that console is not used for function or var names.
  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\MySource\Sniffs\Debug;
  11.  
  12. use PHP_CodeSniffer\Sniffs\Sniff;
  13. use PHP_CodeSniffer\Files\File;
  14.  
  15. class FirebugConsoleSniff implements Sniff
  16. {
  17.  
  18.     /**
  19.      * A list of tokenizers this sniff supports.
  20.      *
  21.      * @var array 
  22.      */
  23.     public $supportedTokenizers = array('JS');
  24.  
  25.  
  26.     /**
  27.      * Returns an array of tokens this test wants to listen for.
  28.      *
  29.      * @return array 
  30.      */
  31.     public function register()
  32.     {
  33.         return array(
  34.                 T_STRING,
  35.                 T_PROPERTY,
  36.                 T_LABEL,
  37.                 T_OBJECT,
  38.                );
  39.  
  40.     }//end register()
  41.  
  42.  
  43.     /**
  44.      * Processes this test, when one of its tokens is encountered.
  45.      *
  46.      * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
  47.      * @param int                         $stackPtr  The position of the current token
  48.      *                                                in the stack passed in $tokens.
  49.      *
  50.      * @return void 
  51.      */
  52.     public function process(File $phpcsFile$stackPtr)
  53.     {
  54.         $tokens $phpcsFile->getTokens();
  55.  
  56.         if (strtolower($tokens[$stackPtr]['content']=== 'console'{
  57.             $error 'Variables, functions and labels must not be named "console"; name may conflict with Firebug internal variable';
  58.             $phpcsFile->addError($error$stackPtr'ConflictFound');
  59.         }
  60.  
  61.     }//end process()
  62.  
  63.  
  64. }//end class

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