@@ -50,6 +50,28 @@ public static function mapConfigVerbosity(string $verbosity): int
5050 return self ::$ verbosityMap [strtolower ($ verbosity )] ?? OutputInterface::VERBOSITY_NORMAL ;
5151 }
5252
53+ /**
54+ * Convert a string to boolean
55+ *
56+ * @param string $string The string to convert
57+ * @param bool $default Either look for true or false values
58+ * @return bool
59+ */
60+ public static function stringToBool (string $ string , bool $ default = false ): bool
61+ {
62+ // convert to lowercase to make it easier to compare
63+ $ string = strtolower ($ string );
64+
65+ // if the default is true, we only look for false values
66+ // if we can't find any, we return true
67+ if ($ default ) {
68+ return !in_array ($ string , ['false ' , 'n ' , 'no ' , '0 ' , 'off ' ]);
69+ }
70+ // if the default is false, we only look for true values,
71+ // and if we can't find any, we return false'
72+ return in_array ($ string , ['true ' , 'y ' , 'yes ' , 'ok ' , '1 ' , 'on ' ]);
73+ }
74+
5375 /**
5476 * Convert a user answer to boolean
5577 *
@@ -58,11 +80,11 @@ public static function mapConfigVerbosity(string $verbosity): int
5880 */
5981 public static function answerToBool (string $ answer ): bool
6082 {
61- return in_array ( strtolower ( $ answer), [ ' y ' , ' yes ' , ' ok ' ] );
83+ return self :: stringToBool ( $ answer, false );
6284 }
6385
6486 /**
65- * Create formatted cli headline
87+ * Create a formatted cli headline
6688 *
6789 * ">>>> HEADLINE <<<<"
6890 * "==== HEADLINE ===="
0 commit comments