Skip to content

Commit 86d411e

Browse files
committed
refactor: add precise array phpdocs for CLI
1 parent 9331fa8 commit 86d411e

4 files changed

Lines changed: 24 additions & 78 deletions

File tree

system/CLI/CLI.php

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ public static function input(?string $prefix = null): string
214214
* // Do not provide options but requires a valid email
215215
* $email = CLI::prompt('What is your email?', null, 'required|valid_email');
216216
*
217-
* @param string $field Output "field" question
218-
* @param list<int|string>|string $options String to a default value, array to a list of options (the first option will be the default value)
219-
* @param array|string|null $validation Validation rules
217+
* @param string $field Output "field" question
218+
* @param list<int|string>|string $options String to a default value, array to a list of options (the first option will be the default value)
219+
* @param list<string>|string|null $validation Validation rules
220220
*
221221
* @return string The user input
222222
*/
@@ -273,10 +273,10 @@ public static function prompt(string $field, $options = null, $validation = null
273273
/**
274274
* prompt(), but based on the option's key
275275
*
276-
* @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
277-
* and the second value the text before asking to select one option. Provide empty string to omit
278-
* @param array $options A list of options (array(key => description)), the first option will be the default value
279-
* @param array|string|null $validation Validation rules
276+
* @param list<string>|string $text Output "field" text or an one or two value array where the first value is the text before listing the options
277+
* and the second value the text before asking to select one option. Provide empty string to omit
278+
* @param array<int|string, string> $options A list of options (array(key => description)), the first option will be the default value
279+
* @param list<string>|string|null $validation Validation rules
280280
*
281281
* @return string The selected key of $options
282282
*/
@@ -302,11 +302,11 @@ public static function promptByKey($text, array $options, $validation = null): s
302302
/**
303303
* This method is the same as promptByKey(), but this method supports multiple keys, separated by commas.
304304
*
305-
* @param string $text Output "field" text or an one or two value array where the first value is the text before listing the options
306-
* and the second value the text before asking to select one option. Provide empty string to omit
307-
* @param array $options A list of options (array(key => description)), the first option will be the default value
305+
* @param string $text Output "field" text or an one or two value array where the first value is the text before listing the options
306+
* and the second value the text before asking to select one option. Provide empty string to omit
307+
* @param array<int|string, string> $options A list of options (array(key => description)), the first option will be the default value
308308
*
309-
* @return array The selected key(s) and value(s) of $options
309+
* @return array<int|string, string> The selected key(s) and value(s) of $options
310310
*/
311311
public static function promptByMultipleKeys(string $text, array $options): array
312312
{
@@ -375,6 +375,8 @@ public static function promptByMultipleKeys(string $text, array $options): array
375375

376376
/**
377377
* Validation for $options in promptByKey() and promptByMultipleKeys(). Return an error if $options is an empty array.
378+
*
379+
* @param array<int|string, string> $options
378380
*/
379381
private static function isZeroOptions(array $options): void
380382
{
@@ -385,6 +387,8 @@ private static function isZeroOptions(array $options): void
385387

386388
/**
387389
* Print each key and value one by one
390+
*
391+
* @param array<int|string, string> $options
388392
*/
389393
private static function printKeysAndValues(array $options): void
390394
{
@@ -404,9 +408,9 @@ private static function printKeysAndValues(array $options): void
404408
/**
405409
* Validate one prompt "field" at a time
406410
*
407-
* @param string $field Prompt "field" output
408-
* @param string $value Input value
409-
* @param array|string $rules Validation rules
411+
* @param string $field Prompt "field" output
412+
* @param string $value Input value
413+
* @param list<string>|string $rules Validation rules
410414
*/
411415
protected static function validate(string $field, string $value, $rules): bool
412416
{
@@ -1025,8 +1029,8 @@ public static function getOptionString(bool $useLongOpts = false, bool $trim = f
10251029
/**
10261030
* Returns a well formatted table
10271031
*
1028-
* @param array $tbody List of rows
1029-
* @param array $thead List of columns
1032+
* @param list<array<int|string, mixed>> $tbody List of rows
1033+
* @param list<string> $thead List of columns
10301034
*
10311035
* @return void
10321036
*/

system/CLI/Console.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public function showHeader(bool $suppress = false)
7575
* unshift it as argument instead.
7676
*
7777
* @param array<int|string, string|null> $params
78+
*
79+
* @return array<int|string, string|null>
7880
*/
7981
private function parseParamsForHelpOption(array $params): array
8082
{

utils/phpstan-baseline/loader.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 1837 errors
1+
# total 1825 errors
22

33
includes:
44
- argument.type.neon

utils/phpstan-baseline/missingType.iterableValue.neon

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,7 @@
1-
# total 1153 errors
1+
# total 1141 errors
22

33
parameters:
44
ignoreErrors:
5-
-
6-
message: '#^Method CodeIgniter\\CLI\\CLI\:\:isZeroOptions\(\) has parameter \$options with no value type specified in iterable type array\.$#'
7-
count: 1
8-
path: ../../system/CLI/CLI.php
9-
10-
-
11-
message: '#^Method CodeIgniter\\CLI\\CLI\:\:printKeysAndValues\(\) has parameter \$options with no value type specified in iterable type array\.$#'
12-
count: 1
13-
path: ../../system/CLI/CLI.php
14-
15-
-
16-
message: '#^Method CodeIgniter\\CLI\\CLI\:\:promptByKey\(\) has parameter \$options with no value type specified in iterable type array\.$#'
17-
count: 1
18-
path: ../../system/CLI/CLI.php
19-
20-
-
21-
message: '#^Method CodeIgniter\\CLI\\CLI\:\:promptByKey\(\) has parameter \$text with no value type specified in iterable type array\.$#'
22-
count: 1
23-
path: ../../system/CLI/CLI.php
24-
25-
-
26-
message: '#^Method CodeIgniter\\CLI\\CLI\:\:promptByKey\(\) has parameter \$validation with no value type specified in iterable type array\.$#'
27-
count: 1
28-
path: ../../system/CLI/CLI.php
29-
30-
-
31-
message: '#^Method CodeIgniter\\CLI\\CLI\:\:promptByMultipleKeys\(\) has parameter \$options with no value type specified in iterable type array\.$#'
32-
count: 1
33-
path: ../../system/CLI/CLI.php
34-
35-
-
36-
message: '#^Method CodeIgniter\\CLI\\CLI\:\:promptByMultipleKeys\(\) return type has no value type specified in iterable type array\.$#'
37-
count: 1
38-
path: ../../system/CLI/CLI.php
39-
40-
-
41-
message: '#^Method CodeIgniter\\CLI\\CLI\:\:prompt\(\) has parameter \$validation with no value type specified in iterable type array\.$#'
42-
count: 1
43-
path: ../../system/CLI/CLI.php
44-
45-
-
46-
message: '#^Method CodeIgniter\\CLI\\CLI\:\:table\(\) has parameter \$tbody with no value type specified in iterable type array\.$#'
47-
count: 1
48-
path: ../../system/CLI/CLI.php
49-
50-
-
51-
message: '#^Method CodeIgniter\\CLI\\CLI\:\:table\(\) has parameter \$thead with no value type specified in iterable type array\.$#'
52-
count: 1
53-
path: ../../system/CLI/CLI.php
54-
55-
-
56-
message: '#^Method CodeIgniter\\CLI\\CLI\:\:validate\(\) has parameter \$rules with no value type specified in iterable type array\.$#'
57-
count: 1
58-
path: ../../system/CLI/CLI.php
59-
60-
-
61-
message: '#^Method CodeIgniter\\CLI\\Console\:\:parseParamsForHelpOption\(\) return type has no value type specified in iterable type array\.$#'
62-
count: 1
63-
path: ../../system/CLI/Console.php
64-
655
-
666
message: '#^Method CodeIgniter\\CodeIgniter\:\:getPerformanceStats\(\) return type has no value type specified in iterable type array\.$#'
677
count: 1

0 commit comments

Comments
 (0)