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

Source for file CamelCapsMethodNameSniff.php

Documentation is available at CamelCapsMethodNameSniff.php

  1. <?php
  2. /**
  3.  * Ensures method names are defined using camel case.
  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\PSR1\Sniffs\Methods;
  11.  
  12. use PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff as GenericCamelCapsFunctionNameSniff;
  13. use PHP_CodeSniffer\Util\Common;
  14. use PHP_CodeSniffer\Files\File;
  15.  
  16. class CamelCapsMethodNameSniff extends GenericCamelCapsFunctionNameSniff
  17. {
  18.  
  19.  
  20.     /**
  21.      * Processes the tokens within 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.      * @param int                         $currScope The position of the current scope.
  27.      *
  28.      * @return void 
  29.      */
  30.     protected function processTokenWithinScope(File $phpcsFile$stackPtr$currScope)
  31.     {
  32.         $methodName $phpcsFile->getDeclarationName($stackPtr);
  33.         if ($methodName === null{
  34.             // Ignore closures.
  35.             return;
  36.         }
  37.  
  38.         // Ignore magic methods.
  39.         if (preg_match('|^__[^_]|'$methodName!== 0{
  40.             $magicPart strtolower(substr($methodName2));
  41.             if (isset($this->magicMethods[$magicPart]=== true
  42.                 || isset($this->methodsDoubleUnderscore[$magicPart]=== true
  43.             {
  44.                 return;
  45.             }
  46.         }
  47.  
  48.         $testName ltrim($methodName'_');
  49.         if ($testName !== '' &&  Common::isCamelCaps($testNamefalsetruefalse=== false{
  50.             $error     'Method name "%s" is not in camel caps format';
  51.             $className $phpcsFile->getDeclarationName($currScope);
  52.             $errorData = array($className.'::'.$methodName);
  53.             $phpcsFile->addError($error$stackPtr'NotCamelCaps'$errorData);
  54.             $phpcsFile->recordMetric($stackPtr'CamelCase method name''no');
  55.         else {
  56.             $phpcsFile->recordMetric($stackPtr'CamelCase method name''yes');
  57.         }
  58.  
  59.     }//end processTokenWithinScope()
  60.  
  61.  
  62.     /**
  63.      * Processes the tokens outside the scope.
  64.      *
  65.      * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being processed.
  66.      * @param int                         $stackPtr  The position where this token was
  67.      *                                                found.
  68.      *
  69.      * @return void 
  70.      */
  71.     protected function processTokenOutsideScope(File $phpcsFile$stackPtr)
  72.     {
  73.  
  74.     }//end processTokenOutsideScope()
  75.  
  76.  
  77. }//end class

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