Skip to content

Commit 54fced5

Browse files
authored
Merge pull request #1586 from WordPress-Coding-Standards/feature/use-upstream-php-reserved-vars-property
ValidVariableName: Defer to the upstream `$phpReservedVars` property (PHPCS 3.3.0)
2 parents 6c056ab + 1c5e627 commit 54fced5

File tree

1 file changed

+3
-25
lines changed

1 file changed

+3
-25
lines changed

WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*
2424
* @since 0.9.0
2525
* @since 0.13.0 Class name changed: this class is now namespaced.
26+
* @since 2.0.0 Defers to the upstream `$phpReservedVars` property.
2627
*
2728
* Last synced with base class June 2018 at commit 78ddbae97cac078f09928bf89e3ab9e53ad2ace0.
2829
* @link https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php
@@ -31,29 +32,6 @@
3132
*/
3233
class ValidVariableNameSniff extends PHPCS_AbstractVariableSniff {
3334

34-
/**
35-
* PHP Reserved Vars.
36-
*
37-
* @since 0.9.0
38-
* @since 0.11.0 Changed visibility from public to protected.
39-
*
40-
* @var array
41-
*/
42-
protected $php_reserved_vars = array(
43-
'_SERVER' => true,
44-
'_GET' => true,
45-
'_POST' => true,
46-
'_REQUEST' => true,
47-
'_SESSION' => true,
48-
'_ENV' => true,
49-
'_COOKIE' => true,
50-
'_FILES' => true,
51-
'GLOBALS' => true,
52-
'http_response_header' => true,
53-
'HTTP_RAW_POST_DATA' => true,
54-
'php_errormsg' => true,
55-
);
56-
5735
/**
5836
* Mixed-case variables used by WordPress.
5937
*
@@ -131,7 +109,7 @@ protected function processVariable( File $phpcs_file, $stack_ptr ) {
131109
$var_name = ltrim( $tokens[ $stack_ptr ]['content'], '$' );
132110

133111
// If it's a php reserved var, then its ok.
134-
if ( isset( $this->php_reserved_vars[ $var_name ] ) ) {
112+
if ( isset( $this->phpReservedVars[ $var_name ] ) ) {
135113
return;
136114
}
137115

@@ -254,7 +232,7 @@ protected function processVariableInString( File $phpcs_file, $stack_ptr ) {
254232

255233
foreach ( $matches[1] as $var_name ) {
256234
// If it's a php reserved var, then its ok.
257-
if ( isset( $this->php_reserved_vars[ $var_name ] ) ) {
235+
if ( isset( $this->phpReservedVars[ $var_name ] ) ) {
258236
continue;
259237
}
260238

0 commit comments

Comments
 (0)