@@ -122,6 +122,30 @@ 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+
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+
125149 /**
126150 * An array of settings that PHPCS and PHPCBF accept.
127151 *
@@ -191,21 +215,6 @@ class Config
191215 */
192216 private $ cliArgs = [];
193217
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-
209218 /**
210219 * Command line values that the user has supplied directly.
211220 *
@@ -429,15 +438,8 @@ public function __construct(array $cliArgs=[], $dieOnUnknownArg=true)
429438 // Look for a default ruleset in the current directory or higher.
430439 $ currentDir = getcwd ();
431440
432- $ defaultFiles = [
433- '.phpcs.xml ' ,
434- 'phpcs.xml ' ,
435- '.phpcs.xml.dist ' ,
436- 'phpcs.xml.dist ' ,
437- ];
438-
439441 do {
440- foreach ($ defaultFiles as $ defaultFilename ) {
442+ foreach (self :: CONFIG_FILENAMES as $ defaultFilename ) {
441443 $ default = $ currentDir .DIRECTORY_SEPARATOR .$ defaultFilename ;
442444 if (is_file ($ default ) === true ) {
443445 $ this ->standards = [$ default ];
@@ -1250,8 +1252,8 @@ public function processLongArgument($arg, $pos)
12501252 $ generatorName = substr ($ arg , 10 );
12511253 $ lowerCaseGeneratorName = strtolower ($ generatorName );
12521254
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 );
12551257 $ validOptions = substr_replace ($ validOptions , ' and ' , strrpos ($ validOptions , ', ' ), 1 );
12561258 $ error = sprintf (
12571259 '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)
12621264 throw new DeepExitException ($ error , ExitCode::PROCESS_ERROR );
12631265 }
12641266
1265- $ this ->generator = $ this -> validGenerators [$ lowerCaseGeneratorName ];
1267+ $ this ->generator = self :: VALID_GENERATORS [$ lowerCaseGeneratorName ];
12661268 $ this ->overriddenDefaults ['generator ' ] = true ;
12671269 } else if (substr ($ arg , 0 , 9 ) === 'encoding= ' ) {
12681270 if (isset ($ this ->overriddenDefaults ['encoding ' ]) === true ) {
0 commit comments