Skip to content

Commit 1f1d3bb

Browse files
committed
PHP 8.3 | Ruleset: fix deprecation notice
On PHP 8.3, using the `-e` (explain) command would show a `Deprecated: 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: ```bash phpcs -e --standard=PSR1 ``` Output without this fix: ``` The PSR1 standard contains 8 sniffs Generic (4 sniffs) ------------------ Generic.Files.ByteOrderMark Deprecated: Increment on non-alphanumeric string is deprecated in D:\000_GitHub\PHPCS\PHP_CodeSniffer\src\Ruleset.php on line 297 Generic.NamingConventions.UpperCaseConstantName Generic.PHP.DisallowAlternativePHPTags Generic.PHP.DisallowShortOpenTag PSR1 (3 sniffs) --------------- PSR1.Classes.ClassDeclaration PSR1.Files.SideEffects PSR1.Methods.CamelCapsMethodName Squiz (1 sniff) ---------------- Squiz.Classes.ValidClassName ``` Output with this fix: ``` The PSR1 standard contains 8 sniffs Generic (4 sniffs) ------------------ Generic.Files.ByteOrderMark Generic.NamingConventions.UpperCaseConstantName Generic.PHP.DisallowAlternativePHPTags Generic.PHP.DisallowShortOpenTag PSR1 (3 sniffs) --------------- PSR1.Classes.ClassDeclaration PSR1.Files.SideEffects PSR1.Methods.CamelCapsMethodName Squiz (1 sniff) ---------------- Squiz.Classes.ValidClassName ``` 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.
1 parent b737635 commit 1f1d3bb

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Ruleset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public function explain()
243243
ob_start();
244244

245245
$lastStandard = null;
246-
$lastCount = '';
246+
$lastCount = 0;
247247
$sniffCount = count($sniffs);
248248

249249
// Add a dummy entry to the end so we loop

0 commit comments

Comments
 (0)