There's a number of places in the WooCommerce codebase where the
built-in function 'round' is executed passing a non-numeric value
(not a number and not a string that can be parsed as a number),
for example round(''). In PHP 7 this yields a value of 0, but in
PHP 8 this throws an error.
This commit adds a 'NumberUtil' class with a static 'round' method,
this method checks if the passed value is numeric and if so it just
executes the built-in function, otherwise it returns 0. And all the
calls to 'round' in the codebase are replaced with 'NumberUtil::round'.
This commit removes three unused methods and one unused property from the WC_CLI_REST_Command class that I found while fixing PHPCS violations in the includes/cli directory.
Adds an additional message when the REST API returns 401 errors to the CLI, so that people properly include the `--user` flag.
To test:
* Run a command without a valid user ID (`wp wc product list`).
* See the additional error message.
* Run a command with a valid user ID, but cause another error, like a product not existing. (`wp wc product get 124124124 --user=1`).
* See that the extra error message is not displayed.
A non-existent variable was being passed to `limit_item_to_fields`, causing a PHP notice to be displayed.
`PHP Notice: Undefined variable: fields in includes/cli/class-wc-cli-rest-command.php on line 183`
This PR passes the correct value.
To Test:
1. Use `wp wc product list --user=1 --fields="sku,name"` on the command-line.
2. Make sure that a PHP notice does not display in your debug log.