lint/style/prefer-empty-string-compare
In the code-quality set. Unsafe fix: it can change behaviour.
What it does
Compare with '' instead of strlen() === 0.
Configuration
[lint.rules]
"style/prefer-empty-string-compare" = "error"
To skip it in some files, add an override or a @pun-ignore-file comment.
Options
| Name | Type | Allowed values | Default | Upstream name |
|---|---|---|---|---|
identical-or-greater-only |
bool |
Any | false |
None (Pun’s own) |
Replaces
string_length_to_empty(php-cs-fixer, risky)StrlenZeroToIdenticalEmptyString(rector)
Merged rules
These old IDs are now this rule. A config that still names one stops with an error. See merged rules.
lint/strings/prefer-empty-string-identical
Rector’s StrlenZeroToIdenticalEmptyStringRector changes only strlen($x) === 0 and strlen($x) > 0 (either side); PHP-CS-Fixer’s string_length_to_empty also changes !== 0, <= 0 and the comparisons with 1. identical-or-greater-only = true keeps to Rector’s forms; pun migrate sets it when the rule comes from rector.php and not from string_length_to_empty. Rector also writes the string first and casts a value whose native type is not a string, which Pun does not.