Repository navigation
Description
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-returntag, that unionsfalsewith any other type.boolandfalsealone are allowed. - The message says to return the value and throw a dedicated exception on failure, and that a
falsefrom a WordPress function is turned into an exception where the call is made.
Out of scope
- Nullable return types and
nullreturns. - Checking what WordPress functions return; the boundary translation stays with review.
Acceptance criteria
- Fixtures: a docblock
@return string|falseand a closure with the same tag fail with the full message asserted;bool,?stringandstringreturns pass. (A nativestring|falsefixture only if the fixture runs on PHP 8; the rule reads the PHPStan type either way.) -
composer lintis green onmain; the principle-10 row ofdocs/architecture-rules.mdnames the rule.
Verification
composer test
composer lintImpact 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
schlessera commentedon Oct 23, 2026
Picking this up on branch
test/91-forbid-false-union-returns.