Skip to content

Commit 5a8eedb

Browse files
committed
Modernize: PEAR/ValidFunctionName: use class constant for constant array
Note: this also affects the `Squiz.NamingConventions.ValidFunctionName` sniff which extends this sniff. That sniff doesn't access the deprecated property directly, but if other sniffs `extend` the Squiz `ValidFunctionName` sniff, they may be affected.
1 parent 13c4878 commit 5a8eedb

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/Standards/PEAR/Sniffs/NamingConventions/ValidFunctionNameSniff.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ class ValidFunctionNameSniff extends AbstractScopeSniff
2020
/**
2121
* A list of all PHP magic methods.
2222
*
23-
* @var array
23+
* @var array<string, true>
2424
*/
25-
protected $magicMethods = [
25+
protected const MAGIC_METHODS = [
2626
'construct' => true,
2727
'destruct' => true,
2828
'call' => true,
@@ -45,9 +45,27 @@ class ValidFunctionNameSniff extends AbstractScopeSniff
4545
/**
4646
* A list of all PHP magic functions.
4747
*
48-
* @var array
48+
* @var array<string, true>
4949
*/
50-
protected $magicFunctions = ['autoload' => true];
50+
protected const MAGIC_FUNCTIONS = ['autoload' => true];
51+
52+
/**
53+
* A list of all PHP magic methods.
54+
*
55+
* @var array<string, true>
56+
*
57+
* @deprecated 4.0.0 Use the ValidFunctionNameSniff::MAGIC_METHODS constant instead.
58+
*/
59+
protected $magicMethods = self::MAGIC_METHODS;
60+
61+
/**
62+
* A list of all PHP magic functions.
63+
*
64+
* @var array<string, true>
65+
*
66+
* @deprecated 4.0.0 Use the ValidFunctionNameSniff::MAGIC_FUNCTIONS constant instead.
67+
*/
68+
protected $magicFunctions = self::MAGIC_FUNCTIONS;
5169

5270

5371
/**
@@ -101,7 +119,7 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop
101119
// Is this a magic method. i.e., is prefixed with "__" ?
102120
if (preg_match('|^__[^_]|', $methodName) !== 0) {
103121
$magicPart = substr($methodNameLc, 2);
104-
if (isset($this->magicMethods[$magicPart]) === true) {
122+
if (isset(static::MAGIC_METHODS[$magicPart]) === true) {
105123
return;
106124
}
107125

@@ -191,7 +209,7 @@ protected function processTokenOutsideScope(File $phpcsFile, $stackPtr)
191209
// Is this a magic function. i.e., it is prefixed with "__".
192210
if (preg_match('|^__[^_]|', $functionName) !== 0) {
193211
$magicPart = strtolower(substr($functionName, 2));
194-
if (isset($this->magicFunctions[$magicPart]) === true) {
212+
if (isset(static::MAGIC_FUNCTIONS[$magicPart]) === true) {
195213
return;
196214
}
197215

0 commit comments

Comments
 (0)