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

Source for file MemberVarScopeSniff.php

Documentation is available at MemberVarScopeSniff.php

  1. <?php
  2. /**
  3.  * Verifies that class members have scope modifiers.
  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\Scope;
  11.  
  12. use PHP_CodeSniffer\Sniffs\AbstractVariableSniff;
  13. use PHP_CodeSniffer\Files\File;
  14. use PHP_CodeSniffer\Util\Tokens;
  15.  
  16. class MemberVarScopeSniff extends AbstractVariableSniff
  17. {
  18.  
  19.  
  20.     /**
  21.      * Processes the function tokens within the class.
  22.      *
  23.      * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.
  24.      * @param int                         $stackPtr  The position where the token was found.
  25.      *
  26.      * @return void 
  27.      */
  28.     protected function processMemberVar(File $phpcsFile$stackPtr)
  29.     {
  30.         $tokens $phpcsFile->getTokens();
  31.  
  32.         $modifier = null;
  33.         for ($i ($stackPtr - 1)$i > 0; $i--{
  34.             if ($tokens[$i]['line'$tokens[$stackPtr]['line']{
  35.                 break;
  36.             else if (isset(Tokens::$scopeModifiers[$tokens[$i]['code']]=== true{
  37.                 $modifier $i;
  38.                 break;
  39.             }
  40.         }
  41.  
  42.         if ($modifier === null{
  43.             $error 'Scope modifier not specified for member variable "%s"';
  44.             $data  = array($tokens[$stackPtr]['content']);
  45.             $phpcsFile->addError($error$stackPtr'Missing'$data);
  46.         }
  47.  
  48.     }//end processMemberVar()
  49.  
  50.  
  51.     /**
  52.      * Processes normal variables.
  53.      *
  54.      * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.
  55.      * @param int                         $stackPtr  The position where the token was found.
  56.      *
  57.      * @return void 
  58.      */
  59.     protected function processVariable(File $phpcsFile$stackPtr)
  60.     {
  61.         /*
  62.             We don't care about normal variables.
  63.         */
  64.  
  65.     }//end processVariable()
  66.  
  67.  
  68.     /**
  69.      * Processes variables in double quoted strings.
  70.      *
  71.      * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.
  72.      * @param int                         $stackPtr  The position where the token was found.
  73.      *
  74.      * @return void 
  75.      */
  76.     protected function processVariableInString(File $phpcsFile$stackPtr)
  77.     {
  78.         /*
  79.             We don't care about normal variables.
  80.         */
  81.  
  82.     }//end processVariableInString()
  83.  
  84.  
  85. }//end class

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