-
Notifications
You must be signed in to change notification settings - Fork 1.5k
PHP 8.1 | Config: fix passing null to non-nullable notice #3761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PHP 8.1 | Config: fix passing null to non-nullable notice #3761
Conversation
Note: the build failure is unrelated to this PR and will be fixed once #3737 has been merged. |
3a98c12
to
91179a4
Compare
91179a4
to
91021e1
Compare
I've updated this PR to include a default value of I've also updated the commit message and the PR description to be in line with this additional change. Compared to the original PR, the main difference is that the "the original input would be an invalid non-numeric value" case is now also handled and will silently ignore the invalid value and fall back to the default width of Suggested changelog entry
|
91021e1
to
23a3e15
Compare
As per issue 3760, if the `stty size` command errors out, `shell_exec()` will return `null`. Per the [documentation](https://www.php.net/manual/en/function.shell-exec.php#refsect1-function.shell-exec-returnvalues), the `shell_exec()` command can also return `false`, which would also be an unusable value (`preg_match()` will not match, so `'auto'` would be cast to int, resulting in `0` being set as the value). If the output of `shell_exec()` would be `null`, PHP as of PHP 8.1 will throw a "passing null to non-nullable" notice. Additionally, if the output from `shell_exec()` would be `false`, the original input would be an invalid non-numeric value or the original input would be `auto`, but the `shell_exec()` command is disabled, the code as-it-was, would set the `reportWidth` to `0`, which is not that helpful. See: https://3v4l.org/GE7sK I've now changed the logic to: * If the received value is `auto`, check if a valid CLI width can be determined and only then use that value. * In all other cases, including when the value is set directly on the object, the value will be validated and if not valid, a default value of width `80` will be used, which is in line with the default width as stated in [the documentation](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options#setting-the-default-report-width). Fixes 3760
23a3e15
to
8bdbd56
Compare
FYI: this fix is included in today's PHP_CodeSniffer 3.8.0 release. As per #3932, development on PHP_CodeSniffer will continue in the PHPCSStandards/PHP_CodeSniffer repository. If you want to stay informed, you may want to start "watching" that repo (or watching releases from that repo). |
As per issue #3760, if the
stty size
command errors out,shell_exec()
will returnnull
. Per the documentation, theshell_exec()
command can also returnfalse
, which would also be an unusable value (preg_match()
will not match, so'auto'
would be cast to int, resulting in0
being set as the value).If the output of
shell_exec()
would benull
, PHP as of PHP 8.1 will throw a "passing null to non-nullable" notice.Additionally, if the output from
shell_exec()
would befalse
, the original input would be an invalid non-numeric value or the original input would beauto
, but theshell_exec()
command is disabled, the code as-it-was, would set thereportWidth
to0
, which is not that helpful. See: https://3v4l.org/GE7sKI've now changed the logic to only update thereportWidth
property value when the received value isauto
AND a valid CLI width could be determined. This solves the originally reported issue + two of the above mentioned additional issues. The only one not solved is "_the original input would be an invalid non-numeric value _", but in that case, it's clear user-error and not something which PHPCS needs to handle.I've now changed the logic to:
auto
, check if a valid CLI width can be determined and only then use that value.80
will be used, which is in line with the default width as stated in the documentation.Fixes #3760