Skip to content

[Strict] Deprecate DisallowedEmptyRuleFixerRector - #8290

Merged
TomasVotruba merged 2 commits into
mainfrom
deprecate-disallowed-empty-rule-fixer
Aug 4, 2026
Merged

[Strict] Deprecate DisallowedEmptyRuleFixerRector#8290
TomasVotruba merged 2 commits into
mainfrom
deprecate-disallowed-empty-rule-fixer

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Deprecates DisallowedEmptyRuleFixerRector.

The rule replaces a single empty() with a chain of isset() + strict comparisons, driven by the inferred union type. The result is noisier than the input:

 final class SomeClass
 {
     private ?string $name;

     public function run(): bool
     {
-        return empty($this->name);
+        return ! isset($this->name) || $this->name === null || $this->name === '';
     }
 }

The real fix is not a longer check, but narrowing the value to a single sole type - then empty() becomes a plain comparison the developer can write themselves:

// after refactoring $name to a sole string type
return $this->name === '';

Removed along with the rule: its test suite, the now unused ExactCompareFactory, UninitializedPropertyAnalyzer and AbstractFalsyScalarRuleFixerRector, and the rule registration in CodeQualityLevel.

The rule turns empty() into long isset()/comparison chains that are harder to read than the original. Refactoring the value to a single sole type is the better fix.
@TomasVotruba
TomasVotruba merged commit 32dea92 into main Aug 4, 2026
64 checks passed
@TomasVotruba
TomasVotruba deleted the deprecate-disallowed-empty-rule-fixer branch August 4, 2026 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant