Skip to content

tooling: forbid return types that union false with a value #91

Closed

Description

@schlessera

Context

Principle 10: inside the plugin every error is an exception; it does not "return false or null to signal a failure". architecture.noWordPressErrorMechanisms covers WP_Error and the logging functions, but nothing covers falsy failure returns. Telling "false means failure" from "false means no" is not decidable in general: ServiceBasedPlugin::dependencies_are_met() returns a legitimate bool (src/Infrastructure/ServiceBasedPlugin.php:1064), and SimpleView::raw() returning null for a missing property with debug mode off (src/Infrastructure/View/SimpleView.php:154-168) is the graceful degradation principle 10 asks for. A return type that unions false with another type, PHP's own string|false shape, is the one form that only ever means "a value, or failure". src/ declares none today (checked 2026-10-23).

Decision (maintainer, 2026-10-23): add the narrow rule: ban T|false unions only. Plain bool and nullable returns stay with review.

Scope

  • A PHPStan rule architecture.noFalseOnFailure: in the plugin's namespace, no method, function, closure or arrow function declares a return type, native (PHP 8 union) or in a @return / @phpstan-return / @psalm-return tag, that unions false with any other type. bool and false alone are allowed.
  • The message says to return the value and throw a dedicated exception on failure, and that a false from a WordPress function is turned into an exception where the call is made.

Out of scope

  • Nullable return types and null returns.
  • Checking what WordPress functions return; the boundary translation stays with review.

Acceptance criteria

  • Fixtures: a docblock @return string|false and a closure with the same tag fail with the full message asserted; bool, ?string and string returns pass. (A native string|false fixture only if the fixture runs on PHP 8; the rule reads the PHPStan type either way.)
  • composer lint is green on main; the principle-10 row of docs/architecture-rules.md names the rule.

Verification

composer test
composer lint

Impact on generated plugins

Tests and tool configuration only; no interface or convention generated plugins rely on changes.

Note 2026-10-23: the ServiceBasedPlugin::dependencies_are_met() citation had drifted from :840, :848 to :1064; the SimpleView::raw() citation still holds.

Activity

  1. added
    type: test
    area: tooling
    priority: p3
    agent-ready
    on Oct 23, 2026
  2. self-assigned this
    on Oct 23, 2026
  3. schlessera commented on Oct 23, 2026

    @schlessera
    MemberAuthor

    Picking this up on branch test/91-forbid-false-union-returns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent-readyarea: toolingpriority: p3type: test

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions