Skip to content

Commit

Permalink
Squiz ValidVariableNameSniff and Zend ValidVariableNameSniff now igno…
Browse files Browse the repository at this point in the history
…re additional PHP reserved vars
  • Loading branch information
gsherwood committed Apr 30, 2014
1 parent a9fa8c1 commit 32e103b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
Expand Up @@ -69,7 +69,9 @@ protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
'_COOKIE',
'_FILES',
'GLOBALS',
'http_response_header'
'http_response_header',
'HTTP_RAW_POST_DATA',
'php_errormsg',
);

// If it's a php reserved var, then its ok.
Expand Down Expand Up @@ -206,7 +208,11 @@ protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $sta
'_COOKIE',
'_FILES',
'GLOBALS',
'http_response_header',
'HTTP_RAW_POST_DATA',
'php_errormsg',
);

if (preg_match_all('|[^\\\]\${?([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)|', $tokens[$stackPtr]['content'], $matches) !== 0) {
foreach ($matches[1] as $varName) {
// If it's a php reserved var, then its ok.
Expand Down
Expand Up @@ -107,4 +107,7 @@ class a
$_FieldParser,
$_key;
}
?>

var_dump($http_response_header);
var_dump($HTTP_RAW_POST_DATA);
var_dump($php_errormsg);
Expand Up @@ -69,7 +69,9 @@ protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
'_COOKIE',
'_FILES',
'GLOBALS',
'http_response_header'
'http_response_header',
'HTTP_RAW_POST_DATA',
'php_errormsg',
);

// If it's a php reserved var, then its ok.
Expand Down Expand Up @@ -213,6 +215,9 @@ protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $sta
'_COOKIE',
'_FILES',
'GLOBALS',
'http_response_header',
'HTTP_RAW_POST_DATA',
'php_errormsg',
);

if (preg_match_all('|[^\\\]\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)|', $tokens[$stackPtr]['content'], $matches) !== 0) {
Expand Down
Expand Up @@ -97,4 +97,7 @@ echo "{$_SERVER['HOSTNAME']} $var_name";

$someObject->{$name};
$someObject->my_function($var_name);
?>

var_dump($http_response_header);
var_dump($HTTP_RAW_POST_DATA);
var_dump($php_errormsg);
2 changes: 2 additions & 0 deletions package.xml
Expand Up @@ -37,6 +37,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Squiz LowercasePHPFunctionsSniff no longer reports errors for namespaced functions
-- Thanks to Max Galbusera for the patch
- Squiz SwitchDeclarationSniff now allows exit() as a breaking statement for case/default
- Squiz ValidVariableNameSniff and Zend ValidVariableNameSniff now ignore additional PHP reserved vars
-- Thanks to Mikuláš Dítě and Adrian Crepaz for the patch
- Sniff code Squiz.WhiteSpace.MemberVarSpacing.After changed to Squiz.WhiteSpace.MemberVarSpacing.Incorrect (request #20241)
- Fixed bug #20200 : Invalid JSON produced with specific error message
- Fixed bug #20204 : Ruleset exclude checks are case sensitive
Expand Down

0 comments on commit 32e103b

Please sign in to comment.