juststeveking/result
A lightweight Result type for PHP and Laravel. Return success or failure values instead of throwing exceptions, chain transformations, and handle errors explicitly. Supports ok/err creation, mapping, and unwrapping for clearer, safer, more testable control flow.
Architecture fit: This package introduces a functional Result/Either monad pattern to a Laravel/PHP codebase. It is a lightweight, dependency-free value-object library — no framework coupling beyond the global helper autoload (which is idiomatic Laravel but technically framework-agnostic). It fits cleanly as an application-layer primitive for explicit error handling in service and domain layers where exceptions are used for control flow. It is not a replacement for Laravel's validation or exception handler; it is complementary.
Integration feasibility: Low friction. Single Composer dependency, autoloaded global helpers (ok(), err(), result_match()), PHPStan/Psalm-ready generics via PHPDoc. Teams can adopt it incrementally in a single bounded context (e.g., one service class or one controller path) without touching the rest of the app. No migrations, no config publishing, no service provider registration implied.
Technical risk:
ResultInterface<T> guarantees erode to mixed.unwrap() throwing UnwrapException reintroduces exception control flow at the boundary — a common foot-gun if teams mix paradigms inconsistently.ok, err) risks collisions with other packages or future helpers; low but real.ComparableResult limited to int|string Ok values — narrow; complex objects can't use equality checks without custom comparison.Key questions: Does the team already have an error-handling convention (exceptions vs. result types) we'd be fragmenting? Is strict PHPStan/Psalm enforcement in CI a prerequisite we can commit to? Who owns the boundary decision of where Result is returned vs. thrown? Is this a single-maintainer package, and what is the bus factor / release cadence?
Stack fit: Native Laravel/PHP fit. Composer install, PSR-4 autoloading, helper functions available globally. Compatible with any PHP 8.1+ project (generics/mixed syntax implies 8.0+, mixed and union types suggest 8.0+; confirm composer.json constraint before adoption).
Migration path: Do not retrofit existing code. Introduce Result at new seams: new service methods, new API endpoints, or a single module. A pragmatic first step is wrapping one external integration call (e.g., a third-party API client) so Ok/Err replaces try/catch at the call site, then evaluating developer ergonomics before broadening.
Compatibility: Coexists with Laravel's exception handler — errors still surface as thrown exceptions unless explicitly caught into Err. Global helpers are additive and non-breaking to existing Laravel helper usage. Watch for collisions if other packages define ok()/err().
Sequencing:
Result vs. throw; how to convert at boundaries (result_match at controller/service edge).Maintenance: Minimal ongoing maintenance — small surface area, no runtime dependencies. However, adoption increases the number of places developers must understand two error paradigms. The real maintenance cost is cognitive and code-review overhead, not the package itself.
Support: Single-maintainer package (JustSteveKing ecosystem) — active but small. Support relies on GitHub issues and the README; no enterprise SLA. Pin the version and audit upgrades; the 1.0.0 line should be reasonably stable per semver.
Scaling: Scales technically (trivial overhead). Team scaling is the risk: new developers from exception-heavy PHP backgrounds will need onboarding on monadic patterns and generics. map/andThen/orElse chains can become unreadable without conventions (the pipeline anti-pattern).
Failure modes:
unwrap() on Err throws UnwrapException — a runtime crash if isOk()/isErr() checks are skipped, defeating the "explicit errors" premise. Lint/review rule needed.Result, some throws — boundaries leak and errors are silently swallowed or double-wrapped.Ramp-up: Low for ok()/err() basics (minutes); moderate for idiomatic andThen/orElse/result_match usage (a half-day of practice); meaningful for establishing team-wide conventions and CI enforcement (a sprint-level effort before benefits show). Recommend an internal README addendum with canonical examples before rolling beyond one team.
How can I help you explore Laravel packages today?