@@ -14,22 +14,23 @@ class Cli {
1414 * @param string $default
1515 * @return string
1616 */
17- public function input ($ prompt , $ validInputs , $ default = '' ){
17+ public function input (string $ prompt , $ validInputs , string $ default = '' ): string
18+ {
1819 echo $ prompt ;
19- $ input = trim (fgets (fopen ('php://stdin ' , 'r ' )));
20+ $ input = trim (fgets (fopen ('php://stdin ' , 'rb ' )));
2021 while (
2122 !isset ($ input ) ||
2223 (
2324 is_array ($ validInputs ) &&
24- !in_array ($ input , $ validInputs )
25+ !in_array ($ input , $ validInputs, true )
2526 ) ||
2627 (
27- $ validInputs == 'is_file ' &&
28+ $ validInputs === 'is_file ' &&
2829 !is_file ($ input )
2930 )
3031 ){
3132 echo $ prompt ;
32- $ input = trim (fgets (fopen ('php://stdin ' , 'r ' )));
33+ $ input = trim (fgets (fopen ('php://stdin ' , 'rb ' )));
3334 if (empty ($ input ) && !empty ($ default )) {
3435 $ input = $ default ;
3536 }
@@ -40,17 +41,19 @@ public function input($prompt, $validInputs, $default = ''){
4041 /**
4142 * @param string $output
4243 */
43- public function output ($ output ){
44- $ out = fopen ('php://output ' , 'w ' );
45- fputs ($ out , $ output );
44+ public function output (string $ output ): void
45+ {
46+ $ out = fopen ('php://output ' , 'wb ' );
47+ fwrite ($ out , $ output );
4648 fclose ($ out );
4749 }
4850
4951 /**
5052 * @param string $string
5153 */
52- public function error ($ string ){
53- $ stdError = fopen ('php://stderr ' , 'w ' );
54+ public function error (string $ string ): void
55+ {
56+ $ stdError = fopen ('php://stderr ' , 'wb ' );
5457 fwrite ($ stdError , $ string );
5558 fclose ($ stdError );
5659 }
0 commit comments