| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* Generic_Sniffs_PHP_LowerCaseConstantSniff.
|
|
|
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: LowerCaseConstantSniff.php 253114 2008-02-18 00:01:06Z squiz $
|
|
|
14 |
* @link http://pear.php.net/package/PHP_CodeSniffer
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Generic_Sniffs_PHP_LowerCaseConstantSniff.
|
|
|
19 |
*
|
|
|
20 |
* Checks that all uses of true, false and null are lowerrcase.
|
|
|
21 |
*
|
|
|
22 |
* @category PHP
|
|
|
23 |
* @package PHP_CodeSniffer
|
|
|
24 |
* @author Greg Sherwood <gsherwood@squiz.net>
|
|
|
25 |
* @author Marc McIntyre <mmcintyre@squiz.net>
|
|
|
26 |
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
|
|
|
27 |
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
|
|
|
28 |
* @version Release: 1.2.1
|
|
|
29 |
* @link http://pear.php.net/package/PHP_CodeSniffer
|
|
|
30 |
*/
|
|
|
31 |
class Generic_Sniffs_PHP_LowerCaseConstantSniff implements PHP_CodeSniffer_Sniff
|
|
|
32 |
{
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
* A list of tokenizers this sniff supports.
|
|
|
36 |
*
|
|
|
37 |
* @var array
|
|
|
38 |
*/
|
|
|
39 |
public $supportedTokenizers = array(
|
|
|
40 |
'PHP',
|
|
|
41 |
'JS',
|
|
|
42 |
);
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
* Returns an array of tokens this test wants to listen for.
|
|
|
46 |
*
|
|
|
47 |
* @return array
|
|
|
48 |
*/
|
|
|
49 |
public function register()
|
|
|
50 |
{
|
|
|
51 |
return array(
|
|
|
52 |
T_TRUE,
|
|
|
53 |
T_FALSE,
|
|
|
54 |
T_NULL,
|
|
|
55 |
);
|
|
|
56 |
|
|
|
57 |
}//end register()
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
/**
|
|
|
61 |
* Processes this sniff, when one of its tokens is encountered.
|
|
|
62 |
*
|
|
|
63 |
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
|
|
|
64 |
* @param int $stackPtr The position of the current token in the
|
|
|
65 |
* stack passed in $tokens.
|
|
|
66 |
*
|
|
|
67 |
* @return void
|
|
|
68 |
*/
|
|
|
69 |
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
|
|
70 |
{
|
|
|
71 |
$tokens = $phpcsFile->getTokens();
|
|
|
72 |
|
|
|
73 |
$keyword = $tokens[$stackPtr]['content'];
|
|
|
74 |
if (strtolower($keyword) !== $keyword) {
|
|
|
75 |
$error = 'TRUE, FALSE and NULL must be lowercase; expected "'.strtolower($keyword).'" but found "'.$keyword.'"';
|
|
|
76 |
$phpcsFile->addError($error, $stackPtr);
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
}//end process()
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
}//end class
|
|
|
83 |
|
|
|
84 |
?>
|