From 86d411e5c83dd4c3d7ee6e8508532aec904f0971 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Tue, 30 Jun 2026 13:00:55 +0800 Subject: [PATCH] refactor: add precise `array` phpdocs for `CLI` --- system/CLI/CLI.php | 36 ++++++----- system/CLI/Console.php | 2 + utils/phpstan-baseline/loader.neon | 2 +- .../missingType.iterableValue.neon | 62 +------------------ 4 files changed, 24 insertions(+), 78 deletions(-) diff --git a/system/CLI/CLI.php b/system/CLI/CLI.php index 3996f31ee349..11f49bbc0c45 100644 --- a/system/CLI/CLI.php +++ b/system/CLI/CLI.php @@ -214,9 +214,9 @@ public static function input(?string $prefix = null): string * // Do not provide options but requires a valid email * $email = CLI::prompt('What is your email?', null, 'required|valid_email'); * - * @param string $field Output "field" question - * @param list|string $options String to a default value, array to a list of options (the first option will be the default value) - * @param array|string|null $validation Validation rules + * @param string $field Output "field" question + * @param list|string $options String to a default value, array to a list of options (the first option will be the default value) + * @param list|string|null $validation Validation rules * * @return string The user input */ @@ -273,10 +273,10 @@ public static function prompt(string $field, $options = null, $validation = null /** * prompt(), but based on the option's key * - * @param array|string $text Output "field" text or an one or two value array where the first value is the text before listing the options - * and the second value the text before asking to select one option. Provide empty string to omit - * @param array $options A list of options (array(key => description)), the first option will be the default value - * @param array|string|null $validation Validation rules + * @param list|string $text Output "field" text or an one or two value array where the first value is the text before listing the options + * and the second value the text before asking to select one option. Provide empty string to omit + * @param array $options A list of options (array(key => description)), the first option will be the default value + * @param list|string|null $validation Validation rules * * @return string The selected key of $options */ @@ -302,11 +302,11 @@ public static function promptByKey($text, array $options, $validation = null): s /** * This method is the same as promptByKey(), but this method supports multiple keys, separated by commas. * - * @param string $text Output "field" text or an one or two value array where the first value is the text before listing the options - * and the second value the text before asking to select one option. Provide empty string to omit - * @param array $options A list of options (array(key => description)), the first option will be the default value + * @param string $text Output "field" text or an one or two value array where the first value is the text before listing the options + * and the second value the text before asking to select one option. Provide empty string to omit + * @param array $options A list of options (array(key => description)), the first option will be the default value * - * @return array The selected key(s) and value(s) of $options + * @return array The selected key(s) and value(s) of $options */ public static function promptByMultipleKeys(string $text, array $options): array { @@ -375,6 +375,8 @@ public static function promptByMultipleKeys(string $text, array $options): array /** * Validation for $options in promptByKey() and promptByMultipleKeys(). Return an error if $options is an empty array. + * + * @param array $options */ private static function isZeroOptions(array $options): void { @@ -385,6 +387,8 @@ private static function isZeroOptions(array $options): void /** * Print each key and value one by one + * + * @param array $options */ private static function printKeysAndValues(array $options): void { @@ -404,9 +408,9 @@ private static function printKeysAndValues(array $options): void /** * Validate one prompt "field" at a time * - * @param string $field Prompt "field" output - * @param string $value Input value - * @param array|string $rules Validation rules + * @param string $field Prompt "field" output + * @param string $value Input value + * @param list|string $rules Validation rules */ protected static function validate(string $field, string $value, $rules): bool { @@ -1025,8 +1029,8 @@ public static function getOptionString(bool $useLongOpts = false, bool $trim = f /** * Returns a well formatted table * - * @param array $tbody List of rows - * @param array $thead List of columns + * @param list> $tbody List of rows + * @param list $thead List of columns * * @return void */ diff --git a/system/CLI/Console.php b/system/CLI/Console.php index 89415e265134..b24562e52d46 100644 --- a/system/CLI/Console.php +++ b/system/CLI/Console.php @@ -75,6 +75,8 @@ public function showHeader(bool $suppress = false) * unshift it as argument instead. * * @param array $params + * + * @return array */ private function parseParamsForHelpOption(array $params): array { diff --git a/utils/phpstan-baseline/loader.neon b/utils/phpstan-baseline/loader.neon index 4efd8a93d7e4..2e67047327fc 100644 --- a/utils/phpstan-baseline/loader.neon +++ b/utils/phpstan-baseline/loader.neon @@ -1,4 +1,4 @@ -# total 1837 errors +# total 1825 errors includes: - argument.type.neon diff --git a/utils/phpstan-baseline/missingType.iterableValue.neon b/utils/phpstan-baseline/missingType.iterableValue.neon index 80d45074b96e..1627bbb4a52a 100644 --- a/utils/phpstan-baseline/missingType.iterableValue.neon +++ b/utils/phpstan-baseline/missingType.iterableValue.neon @@ -1,67 +1,7 @@ -# total 1153 errors +# total 1141 errors parameters: ignoreErrors: - - - message: '#^Method CodeIgniter\\CLI\\CLI\:\:isZeroOptions\(\) has parameter \$options with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/CLI/CLI.php - - - - message: '#^Method CodeIgniter\\CLI\\CLI\:\:printKeysAndValues\(\) has parameter \$options with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/CLI/CLI.php - - - - message: '#^Method CodeIgniter\\CLI\\CLI\:\:promptByKey\(\) has parameter \$options with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/CLI/CLI.php - - - - message: '#^Method CodeIgniter\\CLI\\CLI\:\:promptByKey\(\) has parameter \$text with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/CLI/CLI.php - - - - message: '#^Method CodeIgniter\\CLI\\CLI\:\:promptByKey\(\) has parameter \$validation with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/CLI/CLI.php - - - - message: '#^Method CodeIgniter\\CLI\\CLI\:\:promptByMultipleKeys\(\) has parameter \$options with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/CLI/CLI.php - - - - message: '#^Method CodeIgniter\\CLI\\CLI\:\:promptByMultipleKeys\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/CLI/CLI.php - - - - message: '#^Method CodeIgniter\\CLI\\CLI\:\:prompt\(\) has parameter \$validation with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/CLI/CLI.php - - - - message: '#^Method CodeIgniter\\CLI\\CLI\:\:table\(\) has parameter \$tbody with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/CLI/CLI.php - - - - message: '#^Method CodeIgniter\\CLI\\CLI\:\:table\(\) has parameter \$thead with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/CLI/CLI.php - - - - message: '#^Method CodeIgniter\\CLI\\CLI\:\:validate\(\) has parameter \$rules with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/CLI/CLI.php - - - - message: '#^Method CodeIgniter\\CLI\\Console\:\:parseParamsForHelpOption\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/CLI/Console.php - - message: '#^Method CodeIgniter\\CodeIgniter\:\:getPerformanceStats\(\) return type has no value type specified in iterable type array\.$#' count: 1