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

Source for file ValidFunctionNameSniff.php

Documentation is available at ValidFunctionNameSniff.php

  1. <?php
  2. /**
  3.  * Ensures method names are correct.
  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\NamingConventions;
  11.  
  12. use PHP_CodeSniffer\Standards\PEAR\Sniffs\NamingConventions\ValidFunctionNameSniff as PEARValidFunctionNameSniff;
  13. use PHP_CodeSniffer\Util\Common;
  14. use PHP_CodeSniffer\Files\File;
  15.  
  16. class ValidFunctionNameSniff extends PEARValidFunctionNameSniff
  17. {
  18.  
  19.  
  20.     /**
  21.      * Processes the tokens outside the scope.
  22.      *
  23.      * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being processed.
  24.      * @param int                         $stackPtr  The position where this token was
  25.      *                                                found.
  26.      *
  27.      * @return void 
  28.      */
  29.     protected function processTokenOutsideScope(File $phpcsFile$stackPtr)
  30.     {
  31.         $functionName $phpcsFile->getDeclarationName($stackPtr);
  32.         if ($functionName === null{
  33.             return;
  34.         }
  35.  
  36.         $errorData = array($functionName);
  37.  
  38.         // Does this function claim to be magical?
  39.         if (preg_match('|^__[^_]|'$functionName!== 0{
  40.             $error 'Function name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore';
  41.             $phpcsFile->addError($error$stackPtr'DoubleUnderscore'$errorData);
  42.             return;
  43.         }
  44.  
  45.         if (Common::isCamelCaps($functionNamefalsetruefalse=== false{
  46.             $error 'Function name "%s" is not in camel caps format';
  47.             $phpcsFile->addError($error$stackPtr'NotCamelCaps'$errorData);
  48.         }
  49.  
  50.     }//end processTokenOutsideScope()
  51.  
  52.  
  53. }//end class

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