1 | <?php |
||
35 | class ValidVariableNameSniff extends AbstractVariableSniff |
||
36 | { |
||
37 | |||
38 | /** |
||
39 | * Variable names, that are reserved in PHP. |
||
40 | * |
||
41 | * @var array |
||
42 | */ |
||
43 | protected $phpReservedVars = array( |
||
44 | '_SERVER', |
||
45 | '_GET', |
||
46 | '_POST', |
||
47 | '_REQUEST', |
||
48 | '_SESSION', |
||
49 | '_ENV', |
||
50 | '_COOKIE', |
||
51 | '_FILES', |
||
52 | 'GLOBALS', |
||
53 | 'http_response_header', |
||
54 | 'HTTP_RAW_POST_DATA', |
||
55 | 'php_errormsg', |
||
56 | ); |
||
57 | |||
58 | /** |
||
59 | * Member variable names that break the rules, but are allowed. |
||
60 | * |
||
61 | * @var array |
||
62 | */ |
||
63 | protected $memberExceptions = array( |
||
64 | // From "kBase". |
||
65 | 'Application', |
||
66 | 'Conn', |
||
67 | |||
68 | // From "kEvent". |
||
69 | 'Name', |
||
70 | 'MasterEvent', |
||
71 | 'Prefix', |
||
72 | 'Special', |
||
73 | |||
74 | // From "kDBItem". |
||
75 | 'IDField', |
||
76 | 'TableName', |
||
77 | 'IgnoreValidation', |
||
78 | ); |
||
79 | |||
80 | |||
81 | /** |
||
82 | * Processes this test, when one of its tokens is encountered. |
||
83 | * |
||
84 | * @param File $phpcsFile The file being scanned. |
||
85 | * @param int $stackPtr The position of the current token in the |
||
86 | * stack passed in $tokens. |
||
87 | * |
||
88 | * @return void |
||
89 | */ |
||
90 | 1 | protected function processVariable(File $phpcsFile, $stackPtr) |
|
115 | |||
116 | |||
117 | /** |
||
118 | * Processes class member variables. |
||
119 | * |
||
120 | * @param File $phpcsFile The file being scanned. |
||
121 | * @param int $stackPtr The position of the current token in the |
||
122 | * stack passed in $tokens. |
||
123 | * |
||
124 | * @return void |
||
125 | */ |
||
126 | 1 | protected function processMemberVar(File $phpcsFile, $stackPtr) |
|
179 | |||
180 | |||
181 | /** |
||
182 | * Processes the variable found within a double quoted string. |
||
183 | * |
||
184 | * @param File $phpcsFile The file being scanned. |
||
185 | * @param int $stackPtr The position of the double quoted |
||
186 | * string. |
||
187 | * |
||
188 | * @return void |
||
189 | */ |
||
190 | 1 | protected function processVariableInString(File $phpcsFile, $stackPtr) |
|
228 | |||
229 | |||
230 | /** |
||
231 | * Determines if a variable is in camel caps case. |
||
232 | * |
||
233 | * @param string $string String. |
||
234 | * @param bool $public If true, the first character in the string |
||
235 | * must be an a-z character. If false, the |
||
236 | * character must be an underscore. This |
||
237 | * argument is only applicable if $classFormat |
||
238 | * is false. |
||
239 | * |
||
240 | * @return bool |
||
241 | */ |
||
242 | 1 | protected function isCamelCaps($string, $public = true) |
|
250 | |||
251 | |||
252 | /** |
||
253 | * Determines if a variable is in snake caps case. |
||
254 | * |
||
255 | * @param string $string String. |
||
256 | * |
||
257 | * @return bool |
||
258 | */ |
||
259 | 1 | protected function isSnakeCaps($string) |
|
263 | }//end class |
||
264 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.