| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* Squiz_Sniffs_NamingConventions_ValidFunctionNameSniff.
|
|
|
4 |
*
|
|
|
5 |
* PHP version 5
|
|
|
6 |
*
|
|
|
7 |
* @category PHP
|
|
|
8 |
* @package PHP_CodeSniffer
|
|
|
9 |
* @author Greg Sherwood <gsherwood@squiz.net>
|
|
|
10 |
* @author Marc McIntyre <mmcintyre@squiz.net>
|
|
|
11 |
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
|
|
12 |
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
|
|
13 |
* @version CVS: $Id: ValidFunctionNameSniff.php 240383 2007-07-27 05:38:59Z squiz $
|
|
|
14 |
* @link http://pear.php.net/package/PHP_CodeSniffer
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
if (class_exists('PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff', true) === false) {
|
|
|
18 |
throw new PHP_CodeSniffer_Exception('Class PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff not found');
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* Squiz_Sniffs_NamingConventions_ValidFunctionNameSniff.
|
|
|
23 |
*
|
|
|
24 |
* Ensures method names are correct depending on whether they are public
|
|
|
25 |
* or private, and that functions are named correctly.
|
|
|
26 |
*
|
|
|
27 |
* @category PHP
|
|
|
28 |
* @package PHP_CodeSniffer
|
|
|
29 |
* @author Greg Sherwood <gsherwood@squiz.net>
|
|
|
30 |
* @author Marc McIntyre <mmcintyre@squiz.net>
|
|
|
31 |
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
|
|
32 |
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
|
|
33 |
* @version Release: 1.2.1
|
|
|
34 |
* @link http://pear.php.net/package/PHP_CodeSniffer
|
|
|
35 |
*/
|
|
|
36 |
class Squiz_Sniffs_NamingConventions_ValidFunctionNameSniff extends PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff
|
|
|
37 |
{
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
* Processes the tokens outside the scope.
|
|
|
42 |
*
|
|
|
43 |
* @param PHP_CodeSniffer_File $phpcsFile The file being processed.
|
|
|
44 |
* @param int $stackPtr The position where this token was
|
|
|
45 |
* found.
|
|
|
46 |
*
|
|
|
47 |
* @return void
|
|
|
48 |
*/
|
|
|
49 |
protected function processTokenOutsideScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
|
|
50 |
{
|
|
|
51 |
$functionName = $phpcsFile->getDeclarationName($stackPtr);
|
|
|
52 |
|
|
|
53 |
// Does this function claim to be magical?
|
|
|
54 |
if (preg_match('|^__|', $functionName) !== 0) {
|
|
|
55 |
$magicPart = substr($functionName, 2);
|
|
|
56 |
$error = "Function name \"$functionName\" is invalid; only PHP magic methods should be prefixed with a double underscore.";
|
|
|
57 |
$phpcsFile->addError($error, $stackPtr);
|
|
|
58 |
return;
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
if (PHP_CodeSniffer::isCamelCaps($functionName, false, true, false) === false) {
|
|
|
62 |
$error = "Function name \"$functionName\" is not in camel caps format";
|
|
|
63 |
$phpcsFile->addError($error, $stackPtr);
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
}//end processTokenOutsideScope()
|
|
|
67 |
|
|
|
68 |
|
|
|
69 |
}//end class
|
|
|
70 |
|
|
|
71 |
?>
|