thephpleague / climate

PHP's best friend for the terminal.
http://climate.thephpleague.com
MIT License
1.87k stars 126 forks source link

Negative padding #156

Closed krzysztofrewak closed 4 years ago

krzysztofrewak commented 4 years ago

When I switched my application to php:7.4.0-fpm-alpine, I started receiving warnings that completely ruined possibility to use your library. I was using radio() method and after PHP updates these showed up:

Warning: str_repeat(): Second argument has to be greater than or equal to 0 in /application/vendor/league/climate/src/TerminalObject/Dynamic/Checkbox/Checkbox.php on line 177

They've appeared even with the basic implementation:

$cli = new CLImate();
$cli->radio("Test", [1, 2])->prompt();

For some reason calculated length for padding changed to a negative number (-5 for example above). I mapped $length variable to be always non-negative for Checkbox class' padding.

I had no problems with other components, so I'm leaving them as they are.

duncan3dc commented 4 years ago

Hi @krzysztofrewak thanks for the pull request, this bug was caused by this code using the system object directly instead of via the utility factory which handles a default value when no terminal width is available. A fix for this issue has been released in version 3.5.2 now