Skip to content

Commit 712f6ff

Browse files
committed
Modernize: AbstractVariableSniff: use class constant for constant array
As the property was in the public API, the class constant is also `protected` and the property has been deprecated, to be removed in PHPCS 5.0.
1 parent 601b296 commit 712f6ff

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/Sniffs/AbstractVariableSniff.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ abstract class AbstractVariableSniff extends AbstractScopeSniff
2626
*
2727
* Used by various naming convention sniffs.
2828
*
29-
* @var array
29+
* @var array<string, true>
3030
*/
31-
protected $phpReservedVars = [
31+
protected const PHP_RESERVED_VARS = [
3232
'_SERVER' => true,
3333
'_GET' => true,
3434
'_POST' => true,
@@ -43,6 +43,15 @@ abstract class AbstractVariableSniff extends AbstractScopeSniff
4343
'php_errormsg' => true,
4444
];
4545

46+
/**
47+
* List of PHP Reserved variables.
48+
*
49+
* @var array<string, true>
50+
*
51+
* @deprecated 4.0.0 Use the AbstractVariableSniff::PHP_RESERVED_VARS constant instead.
52+
*/
53+
protected $phpReservedVars = self::PHP_RESERVED_VARS;
54+
4655

4756
/**
4857
* Constructs an AbstractVariableTest.

src/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected function processVariable(File $phpcsFile, $stackPtr)
3434
$varName = ltrim($tokens[$stackPtr]['content'], '$');
3535

3636
// If it's a php reserved var, then its ok.
37-
if (isset($this->phpReservedVars[$varName]) === true) {
37+
if (isset(static::PHP_RESERVED_VARS[$varName]) === true) {
3838
return;
3939
}
4040

@@ -170,7 +170,7 @@ protected function processVariableInString(File $phpcsFile, $stackPtr)
170170
if (preg_match_all('|[^\\\]\${?([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)|', $tokens[$stackPtr]['content'], $matches) !== 0) {
171171
foreach ($matches[1] as $varName) {
172172
// If it's a php reserved var, then its ok.
173-
if (isset($this->phpReservedVars[$varName]) === true) {
173+
if (isset(static::PHP_RESERVED_VARS[$varName]) === true) {
174174
continue;
175175
}
176176

src/Standards/Zend/Sniffs/NamingConventions/ValidVariableNameSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected function processVariable(File $phpcsFile, $stackPtr)
3434
$varName = ltrim($tokens[$stackPtr]['content'], '$');
3535

3636
// If it's a php reserved var, then its ok.
37-
if (isset($this->phpReservedVars[$varName]) === true) {
37+
if (isset(static::PHP_RESERVED_VARS[$varName]) === true) {
3838
return;
3939
}
4040

@@ -176,7 +176,7 @@ protected function processVariableInString(File $phpcsFile, $stackPtr)
176176
if (preg_match_all('|[^\\\]\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)|', $tokens[$stackPtr]['content'], $matches) !== 0) {
177177
foreach ($matches[1] as $varName) {
178178
// If it's a php reserved var, then its ok.
179-
if (isset($this->phpReservedVars[$varName]) === true) {
179+
if (isset(static::PHP_RESERVED_VARS[$varName]) === true) {
180180
continue;
181181
}
182182

0 commit comments

Comments
 (0)