@@ -225,12 +225,12 @@ public static function prompt(string $field, $options = null, $validation = null
225
225
$ extraOutput = '' ;
226
226
$ default = '' ;
227
227
228
- if ($ validation && ! is_array ($ validation ) && ! is_string ($ validation )) {
228
+ if (isset ( $ validation) && ! is_array ($ validation ) && ! is_string ($ validation )) {
229
229
throw new InvalidArgumentException ('$rules can only be of type string|array ' );
230
230
}
231
231
232
232
if (! is_array ($ validation )) {
233
- $ validation = $ validation ? explode ('| ' , $ validation ) : [];
233
+ $ validation = ( $ validation !== null ) ? explode ('| ' , $ validation ) : [];
234
234
}
235
235
236
236
if (is_string ($ options )) {
@@ -348,7 +348,7 @@ public static function promptByMultipleKeys(string $text, array $options): array
348
348
// return the prompt again if $input contain(s) non-numeric character, except a comma.
349
349
// And if max from $options less than max from input,
350
350
// it means user tried to access null value in $options
351
- if (! $ pattern || $ maxOptions < $ maxInput ) {
351
+ if ($ pattern === 0 || $ maxOptions < $ maxInput ) {
352
352
static ::error ('Please select correctly. ' );
353
353
CLI ::newLine ();
354
354
@@ -441,7 +441,7 @@ protected static function validate(string $field, string $value, $rules): bool
441
441
*/
442
442
public static function print (string $ text = '' , ?string $ foreground = null , ?string $ background = null )
443
443
{
444
- if ($ foreground || $ background ) {
444
+ if (( string ) $ foreground !== '' || ( string ) $ background !== '' ) {
445
445
$ text = static ::color ($ text , $ foreground , $ background );
446
446
}
447
447
@@ -457,7 +457,7 @@ public static function print(string $text = '', ?string $foreground = null, ?str
457
457
*/
458
458
public static function write (string $ text = '' , ?string $ foreground = null , ?string $ background = null )
459
459
{
460
- if ($ foreground || $ background ) {
460
+ if (( string ) $ foreground !== '' || ( string ) $ background !== '' ) {
461
461
$ text = static ::color ($ text , $ foreground , $ background );
462
462
}
463
463
@@ -480,7 +480,7 @@ public static function error(string $text, string $foreground = 'light_red', ?st
480
480
$ stdout = static ::$ isColored ;
481
481
static ::$ isColored = static ::hasColorSupport (STDERR );
482
482
483
- if ($ foreground || $ background ) {
483
+ if ($ foreground !== '' || ( string ) $ background !== '' ) {
484
484
$ text = static ::color ($ text , $ foreground , $ background );
485
485
}
486
486
@@ -589,7 +589,7 @@ public static function color(string $text, string $foreground, ?string $backgrou
589
589
throw CLIException::forInvalidColor ('foreground ' , $ foreground );
590
590
}
591
591
592
- if ($ background !== null && ! array_key_exists ($ background , static ::$ background_colors )) {
592
+ if (( string ) $ background !== '' && ! array_key_exists ($ background , static ::$ background_colors )) {
593
593
throw CLIException::forInvalidColor ('background ' , $ background );
594
594
}
595
595
@@ -637,7 +637,7 @@ private static function getColoredText(string $text, string $foreground, ?string
637
637
{
638
638
$ string = "\033[ " . static ::$ foreground_colors [$ foreground ] . 'm ' ;
639
639
640
- if ($ background !== null ) {
640
+ if (( string ) $ background !== '' ) {
641
641
$ string .= "\033[ " . static ::$ background_colors [$ background ] . 'm ' ;
642
642
}
643
643
@@ -654,7 +654,7 @@ private static function getColoredText(string $text, string $foreground, ?string
654
654
*/
655
655
public static function strlen (?string $ string ): int
656
656
{
657
- if ($ string === null ) {
657
+ if (( string ) $ string === '' ) {
658
658
return 0 ;
659
659
}
660
660
@@ -768,7 +768,7 @@ public static function generateDimensions()
768
768
769
769
// Look for the next lines ending in ": <number>"
770
770
// Searching for "Columns:" or "Lines:" will fail on non-English locales
771
- if ($ return === 0 && $ output && preg_match ('/:\s*(\d+)\n[^:]+:\s*(\d+)\n/ ' , implode ("\n" , $ output ), $ matches )) {
771
+ if ($ return === 0 && $ output !== [] && preg_match ('/:\s*(\d+)\n[^:]+:\s*(\d+)\n/ ' , implode ("\n" , $ output ), $ matches )) {
772
772
static ::$ height = (int ) $ matches [1 ];
773
773
static ::$ width = (int ) $ matches [2 ];
774
774
}
@@ -835,7 +835,7 @@ public static function showProgress($thisStep = 1, int $totalSteps = 10)
835
835
*/
836
836
public static function wrap (?string $ string = null , int $ max = 0 , int $ padLeft = 0 ): string
837
837
{
838
- if ($ string === null || $ string === '' ) {
838
+ if (( string ) $ string === '' ) {
839
839
return '' ;
840
840
}
841
841
0 commit comments