1 | <?php |
||
36 | class CodingStandard_Sniffs_NamingConventions_ValidVariableNameSniff extends |
||
37 | PHP_CodeSniffer_Standards_AbstractVariableSniff |
||
38 | { |
||
39 | |||
40 | /** |
||
41 | * Variable names, that are reserved in PHP. |
||
42 | * |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $phpReservedVars = array( |
||
46 | '_SERVER', |
||
47 | '_GET', |
||
48 | '_POST', |
||
49 | '_REQUEST', |
||
50 | '_SESSION', |
||
51 | '_ENV', |
||
52 | '_COOKIE', |
||
53 | '_FILES', |
||
54 | 'GLOBALS', |
||
55 | 'http_response_header', |
||
56 | 'HTTP_RAW_POST_DATA', |
||
57 | 'php_errormsg', |
||
58 | ); |
||
59 | |||
60 | /** |
||
61 | * Member variable names that break the rules, but are allowed. |
||
62 | * |
||
63 | * @var array |
||
64 | */ |
||
65 | protected $memberExceptions = array( |
||
66 | // From "kBase". |
||
67 | 'Application', |
||
68 | 'Conn', |
||
69 | |||
70 | // From "kEvent". |
||
71 | 'Name', |
||
72 | 'MasterEvent', |
||
73 | 'Prefix', |
||
74 | 'Special', |
||
75 | |||
76 | // From "kDBItem". |
||
77 | 'IDField', |
||
78 | 'TableName', |
||
79 | 'IgnoreValidation', |
||
80 | ); |
||
81 | |||
82 | |||
83 | /** |
||
84 | * Processes this test, when one of its tokens is encountered. |
||
85 | * |
||
86 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
87 | * @param int $stackPtr The position of the current token in the |
||
88 | * stack passed in $tokens. |
||
89 | * |
||
90 | * @return void |
||
91 | */ |
||
92 | protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
118 | |||
119 | |||
120 | /** |
||
121 | * Processes class member variables. |
||
122 | * |
||
123 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
124 | * @param int $stackPtr The position of the current token in the |
||
125 | * stack passed in $tokens. |
||
126 | * |
||
127 | * @return void |
||
128 | */ |
||
129 | protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
183 | |||
184 | |||
185 | /** |
||
186 | * Processes the variable found within a double quoted string. |
||
187 | * |
||
188 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
189 | * @param int $stackPtr The position of the double quoted |
||
190 | * string. |
||
191 | * |
||
192 | * @return void |
||
193 | */ |
||
194 | protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
233 | |||
234 | |||
235 | /** |
||
236 | * Determines if a variable is in camel caps case. |
||
237 | * |
||
238 | * @param string $string String. |
||
239 | * @param bool $public If true, the first character in the string |
||
240 | * must be an a-z character. If false, the |
||
241 | * character must be an underscore. This |
||
242 | * argument is only applicable if $classFormat |
||
243 | * is false. |
||
244 | * |
||
245 | * @return bool |
||
246 | */ |
||
247 | protected function isCamelCaps($string, $public=true) |
||
256 | |||
257 | |||
258 | /** |
||
259 | * Determines if a variable is in snake caps case. |
||
260 | * |
||
261 | * @param string $string String. |
||
262 | * |
||
263 | * @return bool |
||
264 | */ |
||
265 | protected function isSnakeCaps($string) |
||
270 | |||
271 | |||
272 | }//end class |
||
273 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.