From 9e11317da741704745ece3161e27f6a6d07b34e0 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 13 Apr 2024 12:20:05 +0200 Subject: [PATCH] Modernize: Util\Help: use constant array in class constant This changes the format/type of a `public` constant, but as the class is `final` and marked as `@internal`, i.e. not in the public API, this should not be regarded as a BC-break. --- src/Config.php | 4 ++-- src/Util/Help.php | 33 +++++++++++++++++++++++++++---- tests/Core/Util/Help/HelpTest.php | 4 ++-- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/Config.php b/src/Config.php index d8e0d19e12..3b4af4d31e 100644 --- a/src/Config.php +++ b/src/Config.php @@ -1512,7 +1512,7 @@ public function printShortUsage($return=false) */ public function printPHPCSUsage() { - $longOptions = explode(',', Help::DEFAULT_LONG_OPTIONS); + $longOptions = Help::DEFAULT_LONG_OPTIONS; $longOptions[] = 'cache'; $longOptions[] = 'no-cache'; $longOptions[] = 'report'; @@ -1538,7 +1538,7 @@ public function printPHPCSUsage() */ public function printPHPCBFUsage() { - $longOptions = explode(',', Help::DEFAULT_LONG_OPTIONS); + $longOptions = Help::DEFAULT_LONG_OPTIONS; $longOptions[] = 'suffix'; $shortOptions = Help::DEFAULT_SHORT_OPTIONS; diff --git a/src/Util/Help.php b/src/Util/Help.php index f58daa349d..0c543f2b94 100644 --- a/src/Util/Help.php +++ b/src/Util/Help.php @@ -34,11 +34,36 @@ final class Help /** * Long options which are available for both the `phpcs` as well as the `phpcbf` command. * - * {@internal This should be a constant array, but those aren't supported until PHP 5.6.} - * - * @var string Comma-separated list of the option names. + * @var array List of the option names. */ - public const DEFAULT_LONG_OPTIONS = 'basepath,bootstrap,colors,encoding,error-severity,exclude,extensions,file,file-list,filter,ignore,ignore-annotations,no-colors,parallel,php-ini,report-width,runtime-set,severity,sniffs,standard,stdin-path,tab-width,version,vv,vvv,warning-severity'; + public const DEFAULT_LONG_OPTIONS = [ + 'basepath', + 'bootstrap', + 'colors', + 'encoding', + 'error-severity', + 'exclude', + 'extensions', + 'file', + 'file-list', + 'filter', + 'ignore', + 'ignore-annotations', + 'no-colors', + 'parallel', + 'php-ini', + 'report-width', + 'runtime-set', + 'severity', + 'sniffs', + 'standard', + 'stdin-path', + 'tab-width', + 'version', + 'vv', + 'vvv', + 'warning-severity', + ]; /** * Minimum screen width. diff --git a/tests/Core/Util/Help/HelpTest.php b/tests/Core/Util/Help/HelpTest.php index de55ebfa47..7772277355 100644 --- a/tests/Core/Util/Help/HelpTest.php +++ b/tests/Core/Util/Help/HelpTest.php @@ -190,7 +190,7 @@ public function testOptionFiltering($longOptions, $shortOptions, $expected) */ public static function dataOptionFiltering() { - $allLongOptions = explode(',', Help::DEFAULT_LONG_OPTIONS); + $allLongOptions = Help::DEFAULT_LONG_OPTIONS; $allLongOptions[] = 'cache'; $allLongOptions[] = 'no-cache'; $allLongOptions[] = 'report'; @@ -248,7 +248,7 @@ public static function dataOptionFiltering() ], ], 'Default options only' => [ - 'longOptions' => explode(',', Help::DEFAULT_LONG_OPTIONS), + 'longOptions' => Help::DEFAULT_LONG_OPTIONS, 'shortOptions' => Help::DEFAULT_SHORT_OPTIONS, 'expected' => [ 'Scan targets' => 8,