@@ -122,6 +122,30 @@ class Config
122
122
'no-cache ' => 'cache ' ,
123
123
];
124
124
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
+
137
+ /**
138
+ * The default configuration file names supported by PHPCS.
139
+ *
140
+ * @var array<string> The supported file names in order of precedence (highest first).
141
+ */
142
+ private const CONFIG_FILENAMES = [
143
+ '.phpcs.xml ' ,
144
+ 'phpcs.xml ' ,
145
+ '.phpcs.xml.dist ' ,
146
+ 'phpcs.xml.dist ' ,
147
+ ];
148
+
125
149
/**
126
150
* An array of settings that PHPCS and PHPCBF accept.
127
151
*
@@ -191,21 +215,6 @@ class Config
191
215
*/
192
216
private $ cliArgs = [];
193
217
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
-
209
218
/**
210
219
* Command line values that the user has supplied directly.
211
220
*
@@ -429,15 +438,8 @@ public function __construct(array $cliArgs=[], $dieOnUnknownArg=true)
429
438
// Look for a default ruleset in the current directory or higher.
430
439
$ currentDir = getcwd ();
431
440
432
- $ defaultFiles = [
433
- '.phpcs.xml ' ,
434
- 'phpcs.xml ' ,
435
- '.phpcs.xml.dist ' ,
436
- 'phpcs.xml.dist ' ,
437
- ];
438
-
439
441
do {
440
- foreach ($ defaultFiles as $ defaultFilename ) {
442
+ foreach (self :: CONFIG_FILENAMES as $ defaultFilename ) {
441
443
$ default = $ currentDir .DIRECTORY_SEPARATOR .$ defaultFilename ;
442
444
if (is_file ($ default ) === true ) {
443
445
$ this ->standards = [$ default ];
@@ -1250,8 +1252,8 @@ public function processLongArgument($arg, $pos)
1250
1252
$ generatorName = substr ($ arg , 10 );
1251
1253
$ lowerCaseGeneratorName = strtolower ($ generatorName );
1252
1254
1253
- if (isset ($ this -> validGenerators [$ lowerCaseGeneratorName ]) === false ) {
1254
- $ validOptions = implode (', ' , $ this -> validGenerators );
1255
+ if (isset (self :: VALID_GENERATORS [$ lowerCaseGeneratorName ]) === false ) {
1256
+ $ validOptions = implode (', ' , self :: VALID_GENERATORS );
1255
1257
$ validOptions = substr_replace ($ validOptions , ' and ' , strrpos ($ validOptions , ', ' ), 1 );
1256
1258
$ error = sprintf (
1257
1259
'ERROR: "%s" is not a valid generator. The following generators are supported: %s. ' .PHP_EOL .PHP_EOL ,
@@ -1262,7 +1264,7 @@ public function processLongArgument($arg, $pos)
1262
1264
throw new DeepExitException ($ error , ExitCode::PROCESS_ERROR );
1263
1265
}
1264
1266
1265
- $ this ->generator = $ this -> validGenerators [$ lowerCaseGeneratorName ];
1267
+ $ this ->generator = self :: VALID_GENERATORS [$ lowerCaseGeneratorName ];
1266
1268
$ this ->overriddenDefaults ['generator ' ] = true ;
1267
1269
} else if (substr ($ arg , 0 , 9 ) === 'encoding= ' ) {
1268
1270
if (isset ($ this ->overriddenDefaults ['encoding ' ]) === true ) {
0 commit comments