Commit 28202cd
committed
PHPCS 4.0: handle converting empty string array values to null
PHPCS 4.0 introduced a change where empty string values in array
properties are converted to `null`. This is documented in the
Version 4.0 Developer Upgrade Guide (https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Version-4.0-Developer-Upgrade-Guide#property-type-casting-has-been-made-more-consistent):
> Array elements can now no longer contain an empty string value
> as that value will be cast to `null`.
This affected the sniffs PrefixAllGlobals and NoSilencedErrors.
Both pass array values to `strtolower()`, which triggers a PHP 8.5
deprecation warning when `null` is passed.
The fix is different for each sniff:
- PrefixAllGlobals: Convert `null` back to empty string at the
start of the validation loop. This preserves the "prefix too short"
error that alerts users about invalid configuration.
- NoSilencedErrors: Filter out `null` values before processing.
Unlike PrefixAllGlobals, this sniff has no validation that
provides user feedback for invalid entries, so filtering is cleaner.
A test case was added to safeguard against the deprecation.1 parent b8a27a3 commit 28202cd
File tree
3 files changed
+14
-0
lines changed- WordPress
- Sniffs
- NamingConventions
- PHP
- Tests/PHP
3 files changed
+14
-0
lines changedLines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1229 | 1229 | | |
1230 | 1230 | | |
1231 | 1231 | | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
1232 | 1235 | | |
1233 | 1236 | | |
1234 | 1237 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
189 | 192 | | |
190 | 193 | | |
191 | 194 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
0 commit comments