Skip to content

Commit 1d23cb9

Browse files
committed
Modernize: Config: use class constant for constant array [1]
1 parent b8d295e commit 1d23cb9

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

src/Config.php

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ class Config
122122
'no-cache' => 'cache',
123123
];
124124

125+
/**
126+
* A list of valid generators.
127+
*
128+
* @var array<string, string> Keys are the lowercase version of the generator name, while values
129+
* are the name of the associated PHP generator class.
130+
*/
131+
private const VALID_GENERATORS = [
132+
'text' => 'Text',
133+
'html' => 'HTML',
134+
'markdown' => 'Markdown',
135+
];
136+
125137
/**
126138
* An array of settings that PHPCS and PHPCBF accept.
127139
*
@@ -191,21 +203,6 @@ class Config
191203
*/
192204
private $cliArgs = [];
193205

194-
/**
195-
* A list of valid generators.
196-
*
197-
* {@internal Once support for PHP < 5.6 is dropped, this property should be refactored into a
198-
* class constant.}
199-
*
200-
* @var array<string, string> Keys are the lowercase version of the generator name, while values
201-
* are the associated PHP generator class.
202-
*/
203-
private $validGenerators = [
204-
'text' => 'Text',
205-
'html' => 'HTML',
206-
'markdown' => 'Markdown',
207-
];
208-
209206
/**
210207
* Command line values that the user has supplied directly.
211208
*
@@ -1250,8 +1247,8 @@ public function processLongArgument($arg, $pos)
12501247
$generatorName = substr($arg, 10);
12511248
$lowerCaseGeneratorName = strtolower($generatorName);
12521249

1253-
if (isset($this->validGenerators[$lowerCaseGeneratorName]) === false) {
1254-
$validOptions = implode(', ', $this->validGenerators);
1250+
if (isset(self::VALID_GENERATORS[$lowerCaseGeneratorName]) === false) {
1251+
$validOptions = implode(', ', self::VALID_GENERATORS);
12551252
$validOptions = substr_replace($validOptions, ' and', strrpos($validOptions, ','), 1);
12561253
$error = sprintf(
12571254
'ERROR: "%s" is not a valid generator. The following generators are supported: %s.'.PHP_EOL.PHP_EOL,
@@ -1262,7 +1259,7 @@ public function processLongArgument($arg, $pos)
12621259
throw new DeepExitException($error, ExitCode::PROCESS_ERROR);
12631260
}
12641261

1265-
$this->generator = $this->validGenerators[$lowerCaseGeneratorName];
1262+
$this->generator = self::VALID_GENERATORS[$lowerCaseGeneratorName];
12661263
$this->overriddenDefaults['generator'] = true;
12671264
} else if (substr($arg, 0, 9) === 'encoding=') {
12681265
if (isset($this->overriddenDefaults['encoding']) === true) {

0 commit comments

Comments
 (0)