@@ -225,12 +225,12 @@ public static function prompt(string $field, $options = null, $validation = null
225225 $ extraOutput = '' ;
226226 $ default = '' ;
227227
228- if ($ validation && ! is_array ($ validation ) && ! is_string ($ validation )) {
228+ if (isset ( $ validation) && ! is_array ($ validation ) && ! is_string ($ validation )) {
229229 throw new InvalidArgumentException ('$rules can only be of type string|array ' );
230230 }
231231
232232 if (! is_array ($ validation )) {
233- $ validation = $ validation ? explode ('| ' , $ validation ) : [];
233+ $ validation = ( $ validation !== null ) ? explode ('| ' , $ validation ) : [];
234234 }
235235
236236 if (is_string ($ options )) {
@@ -441,7 +441,7 @@ protected static function validate(string $field, string $value, $rules): bool
441441 */
442442 public static function print (string $ text = '' , ?string $ foreground = null , ?string $ background = null )
443443 {
444- if ($ foreground || $ background ) {
444+ if (( string ) $ foreground !== '' || ( string ) $ background !== '' ) {
445445 $ text = static ::color ($ text , $ foreground , $ background );
446446 }
447447
@@ -457,7 +457,7 @@ public static function print(string $text = '', ?string $foreground = null, ?str
457457 */
458458 public static function write (string $ text = '' , ?string $ foreground = null , ?string $ background = null )
459459 {
460- if ($ foreground || $ background ) {
460+ if (( string ) $ foreground !== '' || ( string ) $ background !== '' ) {
461461 $ text = static ::color ($ text , $ foreground , $ background );
462462 }
463463
@@ -480,7 +480,7 @@ public static function error(string $text, string $foreground = 'light_red', ?st
480480 $ stdout = static ::$ isColored ;
481481 static ::$ isColored = static ::hasColorSupport (STDERR );
482482
483- if ($ foreground || $ background ) {
483+ if ($ foreground !== '' || ( string ) $ background !== '' ) {
484484 $ text = static ::color ($ text , $ foreground , $ background );
485485 }
486486
@@ -589,7 +589,7 @@ public static function color(string $text, string $foreground, ?string $backgrou
589589 throw CLIException::forInvalidColor ('foreground ' , $ foreground );
590590 }
591591
592- if ($ background !== null && ! array_key_exists ($ background , static ::$ background_colors )) {
592+ if (( string ) $ background !== '' && ! array_key_exists ($ background , static ::$ background_colors )) {
593593 throw CLIException::forInvalidColor ('background ' , $ background );
594594 }
595595
@@ -637,7 +637,7 @@ private static function getColoredText(string $text, string $foreground, ?string
637637 {
638638 $ string = "\033[ " . static ::$ foreground_colors [$ foreground ] . 'm ' ;
639639
640- if ($ background !== null ) {
640+ if (( string ) $ background !== '' ) {
641641 $ string .= "\033[ " . static ::$ background_colors [$ background ] . 'm ' ;
642642 }
643643
@@ -654,7 +654,7 @@ private static function getColoredText(string $text, string $foreground, ?string
654654 */
655655 public static function strlen (?string $ string ): int
656656 {
657- if ($ string === null ) {
657+ if (( string ) $ string === '' ) {
658658 return 0 ;
659659 }
660660
@@ -768,7 +768,7 @@ public static function generateDimensions()
768768
769769 // Look for the next lines ending in ": <number>"
770770 // 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 )) {
772772 static ::$ height = (int ) $ matches [1 ];
773773 static ::$ width = (int ) $ matches [2 ];
774774 }
@@ -835,7 +835,7 @@ public static function showProgress($thisStep = 1, int $totalSteps = 10)
835835 */
836836 public static function wrap (?string $ string = null , int $ max = 0 , int $ padLeft = 0 ): string
837837 {
838- if ($ string === null || $ string === '' ) {
838+ if (( string ) $ string === '' ) {
839839 return '' ;
840840 }
841841
0 commit comments