Skip to content

[TypeDeclaration] Add BoolReturnTypeFromBooleanConstAndStrictReturnsRector for mixed const + strict bool returns - #8498

Merged
TomasVotruba merged 1 commit into
mainfrom
bool-return-type-mixed-const-strict
Sep 16, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
bool-return-type-mixed-const-strict

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Adds return type : bool to methods that mix direct true/false const returns with strict bool expression returns - a case that fell between two existing rules.

The gap

public function checkContext(array|string $context)
{
    if (empty($this->context)) {
        return true;                    // const bool
    }

    return 0 === stripos(/* ... */);    // strict bool expr
}
  • BoolReturnTypeFromBooleanConstReturnsRector fires only when all returns are true/false const.
  • BoolReturnTypeFromBooleanStrictReturnsRector fires only when all returns are strict bool expressions.

A method mixing both kinds matched neither, so no : bool was added.

This rule

Fires only when every return is bool and at least one is a const while at least one is a strict expression. Pure-const and pure-strict stay owned by the existing rules, so the three rules are disjoint and idempotent on each other's output.

Registered in TypeDeclarationLevel right after the strict-returns rule.

@TomasVotruba
TomasVotruba merged commit b8f7480 into main Sep 16, 2026
45 checks passed
@TomasVotruba
TomasVotruba deleted the bool-return-type-mixed-const-strict branch September 16, 2026 09:51
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