PHP 8.3 | Ruleset::explain() fix deprecation notice #3876
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
On PHP 8.3, using the
-e
(explain) command would show aDeprecated: Increment on non-alphanumeric string is deprecated in path/to/src/Ruleset.php on line 297
notice after the very first sniff being listed.As the
$lastCount
variable is used as a counter, it should have an integer default (start) value, not a text string.Fixed now.
Testable via the command-line using the following command:
Output without this fix:
Output with this fix:
👉🏻 Note: yes, I'd like to add some tests for this, but it would be much easier to do so without the (partially unclosed) output buffers being created by this function, so I'm pulling this fix first and will refactor the method and add some tests at some point in the future.
Suggested changelog entry
Explain command: fixed PHP 8.3 deprecation notice
Related issues/external references
Refs: https://wiki.php.net/rfc/saner-inc-dec-operators
Types of changes