Problem/Motivation
I've installed entity_update (3.0.0-rc2, installed via composer), for a Drupal 9.5.3 installation. This is running under PHP 8.1.12.
Running drush upec --types results in a PHP error: "Unsupported operand types: string - int".
<!--break-->
The following information displayed:
sh: tput: not found
[error] TypeError: Unsupported operand types: string - int in Drupal\entity_update\EntityUpdatePrint::drushPrintTable() (line 114 of /var/www/html/web/modules/contrib/entity_update/src/EntityUpdatePrint.php) #0 /var/www/html/web/modules/contrib/entity_update/src/EntityCheck.php(46): Drupal\entity_update\EntityUpdatePrint::drushPrintTable()
Steps to reproduce
Install the module on a platform with PHP 8, with no tput utility installed (e.g., Alpine Linux, popular as a base for docker PHP containers). Run drush upec --types.
Proposed resolution
The error is caused when exec('tput cols') fails, because tput does not exist on the platform.
The result is a null string, which causes a type error in PHP 8 when the expression $cols - 2 is evaluated.
Note: earlier versions of PHP will not throw an error, but produce nonsensical (e.g. negative) results for $cols - 2 .
A solution is to check the result of the call to tput. If this fails, try to call stty size, which often exists when tput is not present. Finally, if neither of those returns a useful result, supply a default width.
Remaining tasks
I will supply a patch which implements the proposed resolution. Let's test this across multiple PHP versions / platforms.
User interface changes
None.
API changes
None.
Data model changes
None.