3333 * The wait() method is mostly testable, as long as you don't give it
3434 * an argument of "0".
3535 * These have been flagged to ignore for code coverage purposes.
36+ *
37+ * @see \CodeIgniter\CLI\CLITest
3638 */
3739class CLI
3840{
3941 /**
4042 * Is the readline library on the system?
4143 *
4244 * @var bool
45+ *
46+ * @deprecated 4.4.2 Should be protected.
47+ * @TODO Fix to camelCase in the next major version.
4348 */
4449 public static $ readline_support = false ;
4550
4651 /**
4752 * The message displayed at prompts.
4853 *
4954 * @var string
55+ *
56+ * @deprecated 4.4.2 Should be protected.
57+ * @TODO Fix to camelCase in the next major version.
5058 */
5159 public static $ wait_msg = 'Press any key to continue... ' ;
5260
@@ -61,6 +69,8 @@ class CLI
6169 * Foreground color list
6270 *
6371 * @var array<string, string>
72+ *
73+ * @TODO Fix to camelCase in the next major version.
6474 */
6575 protected static $ foreground_colors = [
6676 'black ' => '0;30 ' ,
@@ -86,6 +96,8 @@ class CLI
8696 * Background color list
8797 *
8898 * @var array<string, string>
99+ *
100+ * @TODO Fix to camelCase in the next major version.
89101 */
90102 protected static $ background_colors = [
91103 'black ' => '40 ' ,
@@ -177,7 +189,7 @@ public static function init()
177189 * Named options must be in the following formats:
178190 * php index.php user -v --v -name=John --name=John
179191 *
180- * @param string $prefix You may specify a string with which to prompt the user.
192+ * @param string|null $prefix You may specify a string with which to prompt the user.
181193 */
182194 public static function input (?string $ prefix = null ): string
183195 {
@@ -208,9 +220,9 @@ public static function input(?string $prefix = null): string
208220 * // Do not provide options but requires a valid email
209221 * $email = CLI::prompt('What is your email?', null, 'required|valid_email');
210222 *
211- * @param string $field Output "field" question
212- * @param array|string $options String to a default value, array to a list of options (the first option will be the default value)
213- * @param array|string $validation Validation rules
223+ * @param string $field Output "field" question
224+ * @param array|string $options String to a default value, array to a list of options (the first option will be the default value)
225+ * @param array|string|null $validation Validation rules
214226 *
215227 * @return string The user input
216228 *
@@ -255,8 +267,8 @@ public static function prompt(string $field, $options = null, $validation = null
255267 // Read the input from keyboard.
256268 $ input = trim (static ::input ()) ?: $ default ;
257269
258- if ($ validation ) {
259- while (! static ::validate (trim ($ field ), $ input , $ validation )) {
270+ if ($ validation !== [] ) {
271+ while (! static ::validate (' " ' . trim ($ field ) . ' " ' , $ input , $ validation )) {
260272 $ input = static ::prompt ($ field , $ options , $ validation );
261273 }
262274 }
@@ -446,7 +458,7 @@ public static function print(string $text = '', ?string $foreground = null, ?str
446458 }
447459
448460 /**
449- * Outputs a string to the cli on it's own line.
461+ * Outputs a string to the cli on its own line.
450462 *
451463 * @return void
452464 */
@@ -572,10 +584,10 @@ public static function clearScreen()
572584 * Returns the given text with the correct color codes for a foreground and
573585 * optionally a background color.
574586 *
575- * @param string $text The text to color
576- * @param string $foreground The foreground color
577- * @param string $background The background color
578- * @param string $format Other formatting to apply. Currently only 'underline' is understood
587+ * @param string $text The text to color
588+ * @param string $foreground The foreground color
589+ * @param string|null $background The background color
590+ * @param string|null $format Other formatting to apply. Currently only 'underline' is understood
579591 *
580592 * @return string The color coded string
581593 */
@@ -832,7 +844,7 @@ public static function showProgress($thisStep = 1, int $totalSteps = 10)
832844 * width.
833845 *
834846 * If an int is passed into $pad_left, then all strings after the first
835- * will padded with that many spaces to the left. Useful when printing
847+ * will pad with that many spaces to the left. Useful when printing
836848 * short descriptions that need to start on an existing line.
837849 */
838850 public static function wrap (?string $ string = null , int $ max = 0 , int $ padLeft = 0 ): string
@@ -849,7 +861,7 @@ public static function wrap(?string $string = null, int $max = 0, int $padLeft =
849861 $ max = self ::getWidth ();
850862 }
851863
852- $ max = $ max - $ padLeft ;
864+ $ max -= $ padLeft ;
853865
854866 $ lines = wordwrap ($ string , $ max , PHP_EOL );
855867
@@ -1076,8 +1088,8 @@ public static function table(array $tbody, array $thead = [])
10761088 foreach ($ tableRows [$ row ] as $ col ) {
10771089 $ diff = $ maxColsLengths [$ column ] - static ::strlen ($ col );
10781090
1079- if ($ diff ) {
1080- $ tableRows [$ row ][$ column ] = $ tableRows [ $ row ][ $ column ] . str_repeat (' ' , $ diff );
1091+ if ($ diff !== 0 ) {
1092+ $ tableRows [$ row ][$ column ] .= str_repeat (' ' , $ diff );
10811093 }
10821094
10831095 $ column ++;
0 commit comments