Skip to content

[EarlyReturn] Deprecate ReturnBinaryOrToEarlyReturnRector - #8302

Merged
TomasVotruba merged 1 commit into
mainfrom
deprecate-return-binary-or-to-early-return
Aug 5, 2026
Merged

[EarlyReturn] Deprecate ReturnBinaryOrToEarlyReturnRector#8302
TomasVotruba merged 1 commit into
mainfrom
deprecate-return-binary-or-to-early-return

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Splitting a single || return into a chain of early returns makes the code longer and harder to follow, not clearer.

 class SomeClass
 {
     public function accept()
     {
-        return $this->something() || $this->somethingElse();
+        if ($this->something()) {
+            return true;
+        }
+        return (bool) $this->somethingElse();
     }
 }

The "before" is a single readable boolean expression. The "after" is 4 lines, adds a (bool) cast and requires reading control flow to get the same meaning.

Follows the same path as #8299.

  • rule now implements DeprecatedInterface and throws on refactor()
  • removed from early-return set
  • rule tests removed
  • dropped now-unused CallAnalyzer::doesIfHasObjectCall() and AssignAndBinaryMap::getTruthyExpr()

@TomasVotruba
TomasVotruba merged commit d12949c into main Aug 5, 2026
64 checks passed
@TomasVotruba
TomasVotruba deleted the deprecate-return-binary-or-to-early-return branch August 5, 2026 22:58
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