3
* PSR1_Sniffs_Methods_CamelCapsMethodNameSniff.
8
* @package PHP_CodeSniffer
9
* @author Greg Sherwood <gsherwood@squiz.net>
10
* @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
11
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
12
* @link http://pear.php.net/package/PHP_CodeSniffer
15
if (class_exists('Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff', true) === false) {
16
throw new PHP_CodeSniffer_Exception('Class Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff not found');
20
* PSR1_Sniffs_Methods_CamelCapsMethodNameSniff.
22
* Ensures method names are defined using camel case.
25
* @package PHP_CodeSniffer
26
* @author Greg Sherwood <gsherwood@squiz.net>
27
* @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
28
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
29
* @version Release: 1.5.3
30
* @link http://pear.php.net/package/PHP_CodeSniffer
32
class PSR1_Sniffs_Methods_CamelCapsMethodNameSniff extends Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff
36
* Constructs a PSR1_Sniffs_Methods_CamelCapsMethodNameSniff.
38
public function __construct()
40
parent::__construct(array(T_CLASS, T_INTERFACE, T_TRAIT), array(T_FUNCTION), true);
46
* Processes the tokens within the scope.
48
* @param PHP_CodeSniffer_File $phpcsFile The file being processed.
49
* @param int $stackPtr The position where this token was
51
* @param int $currScope The position of the current scope.
55
protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
57
$methodName = $phpcsFile->getDeclarationName($stackPtr);
58
if ($methodName === null) {
63
// Ignore magic methods.
64
$magicPart = strtolower(substr($methodName, 2));
65
if (in_array($magicPart, array_merge($this->magicMethods, $this->methodsDoubleUnderscore)) !== false) {
69
$testName = ltrim($methodName, '_');
70
if (PHP_CodeSniffer::isCamelCaps($testName, false, true, false) === false) {
71
$error = 'Method name "%s" is not in camel caps format';
72
$className = $phpcsFile->getDeclarationName($currScope);
73
$errorData = array($className.'::'.$methodName);
74
$phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $errorData);
77
}//end processTokenWithinScope()
81
* Processes the tokens outside the scope.
83
* @param PHP_CodeSniffer_File $phpcsFile The file being processed.
84
* @param int $stackPtr The position where this token was
89
protected function processTokenOutsideScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
93
}//end processTokenOutsideScope()